﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portal.Core;
using Portal.Cms.Model;
using Portal.Cms.Bussiness;
using Portal.Web.Utility;
using Portal.Cms.Utility;
using Portal.Utility;
using DocumentSearchServiceModel;
using DocumentSearch32Lib;
using Jint;
using System.Net;

using System.Web;
using System.IO;



namespace UNBP.VBPQ.RenderService
{
    public class VBPQWebRenderBll
    {
        public static string GetNewsCategoryUrl(string SiteId, string Alias, string aspx)
        {
            return
                aspx + "?Alias=" + Alias;
        }

        public static string GetArticleUrl(string SiteId, string Id)
        {
            return
                "vhtml.aspx?article=" + Id;
        }

        public static string GetNewsUrl(string SiteId, string Id, string BackAspx)
        {
            return
                "newsdetail.aspx?article=" + Id + "&BackAspx=" + BackAspx;
        }

        public static string GetProductDetailsUrl(string SiteId, string Id)
        {
            return
                "productdetails.aspx?article=" + Id;
        }

        public static string GetUrlDetails(string belongSite, string Subject, string ShortId, SiteParam OSiteParam)
        {
            Subject = Portal.Environment.Environments.ConvertSubject(Subject);
            string HttpDataRoot = WebConfig.GetConfigFromXml(OSiteParam, "HttpRoot");
            string Url = HttpDataRoot + "/" + belongSite + "/" + Subject + "-nd-" + ShortId + "." + Portal.Environment.Environments.Extension;
            return Url;
        }

        public static string GetUrlFilters(string belongSite, string Subject, string ShortId, string SiteId, string conditionTitle)
        {
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            Subject = Portal.Environment.Environments.ConvertSubject(Subject);
            string HttpDataRoot = WebConfig.GetConfigFromXml(OSiteParam, "HttpRoot");
            string Url = HttpDataRoot + "/" + belongSite + "/" + Subject + "-" + conditionTitle + "-" + ShortId + "." + Portal.Environment.Environments.Extension;
            return Url;
        }

        public static AjaxOut RenderNews(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);

                CmsDataCls[] CmsData = ReadingServiceBll.ReadingTopListNewsForAlias(SiteId, ORenderInfo.Alias, ORenderInfo.Top, ORenderInfo.ActiveSortIndex);
                string Html =
                    " <h2><a href=\"" + GetNewsCategoryUrl(SiteId, ORenderInfo.Alias, ORenderInfo.JumpPageAspx) + "\">" + ORenderInfo.Title + "</a></h2> \r\n" +
                    " <div class=\"pa15\"> \r\n" +
                    " 	<ul> \r\n";
                for (int iIndex = 0; iIndex < CmsData.Length; iIndex++)
                {
                    Html +=
                    " 		<li class=\"new\"><a href=\"" + GetNewsUrl(SiteId, CmsData[iIndex].DataId, ORenderInfo.JumpPageAspx) + "\">" + CmsData[iIndex].Subject + "</a><span class=\"date\">(" + CmsData[iIndex].EntryDate.ToString("dd/MM/yyyy") + ")</span></li> \r\n";
                }
                Html +=
                    " 	</ul> \r\n" +
                    " </div> \r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderHomeIntroduction(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string CompanyName = WebConfig.GetConfigFromXml(OSiteParam, "CompanyName");
                string CompanyTel = WebConfig.GetConfigFromXml(OSiteParam, "CompanyTel");
                string CompanyFax = WebConfig.GetConfigFromXml(OSiteParam, "CompanyFax");
                string CompanyEmail = WebConfig.GetConfigFromXml(OSiteParam, "CompanyEmail");
                string CompanyEmailText = WebConfig.GetConfigFromXml(OSiteParam, "CompanyEmailText");
                string CompanyAddress = WebConfig.GetConfigFromXml(OSiteParam, "CompanyAddress");
                string CompanyWebSite = WebConfig.GetConfigFromXml(OSiteParam, "CompanyWebSite");
                string Html =
                    " <div class=\"mabottom15\"> \r\n" +
                    "     <img class=\"ftl maright10\" src=\"images/company.jpg\" />\r\n" +
                    "       <h3 href=\"#\">Headquarter</h3>\r\n" +
                    "       <p><b></b><br>\r\n" +
                    " 	    <b>Tel:</b> " + CompanyTel + "  - <b>Fax:</b> " + CompanyFax + " <br>\r\n" +
                    " 	    <b>Email:</b><a href=\"mailto:" + CompanyEmail + "\">" + CompanyEmailText + "</a> <br>\r\n" +
                    " 	    <b>Address:</b> " + CompanyAddress + "\r\n" +
                    "     </p>\r\n" +
                    "     <div class=\"clr\"></div>\r\n" +
                    " </div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderHtml(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias cho bài viết Html!");
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                CmsDataCls CmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, ORenderInfo.Alias);
                if (CmsData == null) throw new Exception("Không tìm thấy bài viết. Truy cập không hợp lệ!");
                string ImageUrl = CmsData.GetAvatarUrl(SiteId, HttpDataRoot);

                string Html =
                             " <h3 href=\"#\">" + ORenderInfo.Title + "</h3>\r\n" +
                             " <span>" + CmsData.Description + "</span>\r\n" +
                            "  <a href=\"" + GetArticleUrl(SiteId, CmsData.DataId) + "\" class=\"readmore\">Read more...</a>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        public static AjaxOut RenderDataImage(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                CmsDataCls[] CmsData = ReadingServiceBll.ReadingTopListNewsForAlias(SiteId, ORenderInfo.Alias, ORenderInfo.Top, ORenderInfo.ActiveSortIndex);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                string Html = "";
                for (int iIndex = 0; iIndex < CmsData.Length; iIndex++)
                {
                    string ImageUrl = CmsData[iIndex].GetAvatarUrl(SiteId, HttpDataRoot);
                    if (ORenderInfo.Equals("default"))
                    {
                        Html += "<img class=\"sthumb ftl maright10\" src=\"" + ImageUrl + "\" />";
                    }
                    if (ORenderInfo.RenderType.ToLower().Equals("history") || ORenderInfo.RenderType.ToLower().Equals("activity"))
                    {
                        Html += "<img class=\"sthumb ftl maright10\" src=\"" + ImageUrl + "\" />";
                    }
                    if (ORenderInfo.RenderType.ToLower().Equals("certificate"))
                    {
                        Html += "<img class=\"sthumb ftl maright10\" src=\"" + ImageUrl + "\" />";
                    }
                }
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderDataGallery(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                CmsDataCls[] CmsData = ReadingServiceBll.ReadingTopListNewsForAlias(SiteId, ORenderInfo.Alias, ORenderInfo.Top, ORenderInfo.ActiveSortIndex);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                string Html =
                    " <h2><a href=\"#\">" + ORenderInfo.Title + "</a></h2> \r\n" +
                    "	<div class=\"pa5\"> \r\n" +
                    "			<div class=\"photonav\"> \r\n" +
                    "				<a class=\"nextvphoto\" href=\"javascript:void();\"></a> \r\n" +
                    "				<a class=\"prevvphoto\" href=\"javascript:void();\"></a> \r\n" +
                    "			</div> \r\n" +
                    "			<div class=\"mcbody\"> \r\n" +
                    "				<div id=\"phongsuanh\"> \r\n" +
                    "					<ul class=\"vphoto\"> \r\n";
                for (int iIndex = 0; iIndex < CmsData.Length; iIndex++)
                {
                    string ImageUrl = CmsData[iIndex].GetAvatarUrl(SiteId, HttpDataRoot);
                    Html +=
                            " <li> \r\n" +
                            " 	<a href=\"/Portal/vi/cpv-khibanhtrungthulanchiem-cpvnd-276618-cpvnc-70-cpvd-14092012-cpvsite-.html\">\r\n" +
                            " 		<img src=\"" + ImageUrl + "\" class=\"gathumb\" alt=\"" + CmsData[iIndex].Description + "\" title=\"" + CmsData[iIndex].Description + "\" />\r\n" +
                            " 		<span alt=\"" + CmsData[iIndex].Description + "\" title=\"" + CmsData[iIndex].Description + "\">" + CmsData[iIndex].Subject + "</span>\r\n" +
                            " 	</a>\r\n" +
                            " 	<div class=\"clr\"></div>\r\n" +
                            " </li>\r\n";
                }
                Html +=
                            "			</ul> \r\n" +
                            "		</div> \r\n" +
                            "	</div> \r\n" +
                            "</div> \r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        public static AjaxOut RenderDataPartner(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                CmsDataCls[] CmsData = ReadingServiceBll.ReadingTopListNewsForAlias(SiteId, ORenderInfo.Alias, ORenderInfo.Top, ORenderInfo.ActiveSortIndex);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                string Html =
                    " <h2><a href=\"#\">" + ORenderInfo.Title + "</a></h2> \r\n" +
                    " <div class=\"pa6\"> \r\n";
                for (int iIndex = 0; iIndex < CmsData.Length; iIndex++)
                {
                    string ImageUrl = CmsData[iIndex].GetAvatarUrl(SiteId, HttpDataRoot);
                    Html +=
                            " 	<a target=\"" + CmsData[iIndex].Target + "\" href=\"" + CmsData[iIndex].Url + "\">\r\n" +
                            " 		<img src=\"" + ImageUrl + "\" class=\"gathumb\" alt=\"" + CmsData[iIndex].Description + "\" title=\"" + CmsData[iIndex].Description + "\" />\r\n" +
                            " 	</a>\r\n";
                }
                Html +=
                            "</div> \r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        public static AjaxOut RenderDataVideo(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias cho bài viết Html!");
                CmsDataCls CmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, ORenderInfo.Alias);
                if (CmsData == null) throw new Exception("Không tìm thấy bài viết. Truy cập không hợp lệ!");
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                string VideoUrl = CmsData.GetAvatarUrl(SiteId, HttpDataRoot);

                string Html =
                    " <h2><a href=\"video.html\">" + ORenderInfo.Title + "</a></h2> \r\n" +
                    " 	<div class=\"video_c\"> \r\n" +
                    " 		<div class=\"videoplayer\"> \r\n" +
                    " 			<object classid=\"clsid:999AF809-05DE-47ED-9CBE-CFF04DAE7B64\" width=\"220px\" height=\"194px\" id=\"player1\" name=\"player1\"> \r\n" +
                    " 				<param name=\"movie\" value=\"videos/Javascripts/player.swf\"> \r\n" +
                    " 				<param name=\"allowfullscreen\" value=\"true\"> \r\n" +
                    " 				<param name=\"menu\" value=\"false\"> \r\n" +
                    " 				<param name=\"allowscriptaccess\" value=\"always\"> \r\n" +
                    " 				<param name=\"flashvars\" value=\"" + VideoUrl + "\"> \r\n" +
                    " 				<embed id=\"999AF809-05DE-47ED-9CBE-CFF04DAE7B64\" name=\"player1\" src=\"videos/Javascripts/player.swf\" width=\"220px\" height=\"194px\" allowscriptaccess=\"always\" menu=\"false\" allowfullscreen=\"true\" flashvars=\"file=" + VideoUrl + "\"> \r\n" +
                    " 			</object> \r\n" +
                    " 		  <div class=\"clrfix\"> \r\n" +
                    " 		  </div> \r\n" +
                    " 		</div> \r\n" +
                    " 	</div> \r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        public static AjaxOut RenderDataImageLink(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);

                CmsDataCls[] CmsData = ReadingServiceBll.ReadingTopListNewsForAlias(SiteId, ORenderInfo.Alias, ORenderInfo.Top, ORenderInfo.ActiveSortIndex);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                string Html =
                    " <div class=CssImageLink> \r\n" +
                    " <ul>\r\n";
                for (int iIndex = 0; iIndex < CmsData.Length; iIndex++)
                {
                    string ImageUrl = CmsData[iIndex].GetAvatarUrl(SiteId, HttpDataRoot);
                    Html +=
                            " 	<li><a target=\"" + CmsData[iIndex].Target + "\" href=\"" + CmsData[iIndex].Url + "\"><img src=\"" + ImageUrl + "\" class=\"imagelink\" alt=\"" + CmsData[iIndex].Description + "\" title=\"" + CmsData[iIndex].Description + "\" /></li>\r\n";
                }
                Html +=
                    "</ul> \r\n" +
                    "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }




        public static AjaxOut RenderViewHtml(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {

                string Alias = ORenderInfo.Alias;
                if (ORenderInfo.FromRequest == 1)
                {
                    Alias = WebEnvironments.Request(SiteId, "article");
                }
                if (string.IsNullOrEmpty(Alias)) throw new Exception("Tham số không hợp lệ!");

                //GroupDataCls OGroupData = CmsProcessBll.CreateGroupDataModel(SiteId, ORenderInfo.Alias);
                //if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                if (string.IsNullOrEmpty(Alias)) throw new Exception("Chưa xác định Alias cho bài viết Html!");
                CmsDataCls CmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, Alias);
                if (CmsData == null) throw new Exception("Không tìm thấy bài viết. Truy cập không hợp lệ!");
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                string VideoUrl = CmsData.GetAvatarUrl(SiteId, HttpDataRoot);
                if (string.IsNullOrEmpty(ORenderInfo.Title)) ORenderInfo.Title = "Content";
                string Html =
                    " <div class=\"white drop120\"> \r\n" +
                    " 	<h2><a href=\"#\">" + ORenderInfo.Title + "</a></h2> \r\n" +
                    " 	<div class=\"pa20\"> \r\n" +
                    " 		<div class=\"borbottom pabottom10 mabottom20\"> \r\n" +
                    " 			<h3 class=\"bold large\">" + CmsData.Subject + "</h3>\r\n" +
                    "			<span class=\"small\"><span class=\"red\">" + CmsData.EntryDate.ToString("HH:mm") + "</span> <span class=\"grey\">  |  20/11/2012</span></span>\r\n" +//<span class=\"tyni maleft5 round3 pa3 pending\">recruiting</span>
                    "			<div class=\"clr pabottom10\"></div>\r\n" +
                                    CmsData.Body +
                    "           </div>\r\n" +
                    "       </div>\r\n" +
                    "   </div>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderDataNewsCat(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                int CurrentPageIndex = 0;
                try
                {
                    CurrentPageIndex = int.Parse(WebEnvironments.Request(SiteId, "p"));
                }
                catch { }

                string k = (string)WebEnvironments.Request(SiteId, "k");
                string fd = (string)WebEnvironments.Request(SiteId, "fd");
                string td = (string)WebEnvironments.Request(SiteId, "td");
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                CmsDataCls[] CmsData = VBPQBussinessProcessBll.SearchData(SiteId, ORenderInfo.Alias, k, fd, td, ORenderInfo.ActiveSortIndex);
                VBPQReturnPaging OVBPQReturnPaging = VBPQPagingUtilities.GetPaging(CmsData.Length, CurrentPageIndex, 10, 10, "NextPage", 0);
                if (string.IsNullOrEmpty(ORenderInfo.Title))
                {
                    ORenderInfo.Title = OGroupData.GroupDataName;
                }
                string DataPathRoot = WebConfig.DataPathRoot(OSiteParam);
                string Html =
                    " <script language=javascript>\r\n" +
                    "   function NextPage(CurrentPageIndex)\r\n" +
                    "   {\r\n" +
                    "       Alias=document.getElementById('txtAlias').value;\r\n" +
                    "       JumpPageAspx=document.getElementById('txtJumpPageAspx').value;\r\n" +
                    "       window.open('" + ORenderInfo.JumpPageAspx + "?alias='+Alias+'&p='+CurrentPageIndex,'_self');\r\n" +
                    "   }\r\n" +
                    " </script>\r\n" +
                    " <input type=hidden id=txtAlias value=\"" + ORenderInfo.Alias + "\">\r\n" +
                    " <input type=hidden id=txtJumpPageAspx value=\"" + ORenderInfo.JumpPageAspx + "\">\r\n" +
                    " <div class=CssListCategory>\r\n" +
                    " <h3><a href=\"#\">" + ORenderInfo.Title + "</a></h3>";
                if (string.IsNullOrEmpty(k))
                {
                    Html += " <div class=CssNewsHeading>Tìm thấy " + CmsData.Length.ToString("#,##0") + " dữ liệu theo điều kiện lọc</div>\r\n";
                }
                else
                {
                    Html += " <div class=CssNewsHeading>Tổng số có " + CmsData.Length.ToString("#,##0") + " dữ liệu trong chuyên mục</div>\r\n";
                }
                Html +=
                    " <table>";
                for (int iIndex = OVBPQReturnPaging.StartIndex; iIndex < OVBPQReturnPaging.EndIndex; iIndex++)
                {
                    string ImageUrl = CmsData[iIndex].GetAvatarUrl(SiteId, HttpDataRoot);
                    string ImageText = "";
                    if (ORenderInfo.ShowImage == 1)
                    {
                        ImageText = "<img class=imgthumb src=\"" + ImageUrl + "\"></img>";
                        if (!CmsData[iIndex].HasImage(SiteId, DataPathRoot))
                        {
                            if (string.IsNullOrEmpty(ORenderInfo.Image))
                            {
                                ImageText = "<img class=imgthumb src=\"images/noimage.png\"></img>";
                            }
                            else
                            {
                                ImageText = "<img class=imgthumb src=\"" + ORenderInfo.Image + "\"></img>";
                            }
                        }
                    }

                    Html +=
                     " <tr> \r\n";
                    if (ORenderInfo.ShowImage == 1)
                    {
                        Html +=
                            "    <td style=\"width:80px;vertical-align:top\">" + ImageText + "</td> \r\n";
                    }
                    Html +=
                     "    <td> \r\n" +
                     "        <div class=NewsTitle><a href=\"" + GetNewsUrl(SiteId, CmsData[iIndex].DataId, ORenderInfo.JumpPageAspx) + "\">" + CmsData[iIndex].Subject + "</a></div> \r\n" +
                     "        <div>" + CmsData[iIndex].EntryDate.ToString("HH:mm") + " | " + CmsData[iIndex].EntryDate.ToString("dd/MM/yyyy") + "</div> \r\n" +
                     "        <div>" + FunctionUtilities.CutText(CmsData[iIndex].Description, 60) + "</div> \r\n" +
                     "    </td> \r\n" +
                     " </tr> \r\n";
                }
                Html += "</table>\r\n" +
                    OVBPQReturnPaging.PagingText + "<br/>" +
                    "<div class=\"clr\"></div>\r\n" +
                    "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        public static string GetDayText(DateTime EntryDate)
        {
            if (EntryDate.DayOfWeek == DayOfWeek.Monday) return "Thứ hai";
            if (EntryDate.DayOfWeek == DayOfWeek.Tuesday) return "Thứ ba";
            if (EntryDate.DayOfWeek == DayOfWeek.Wednesday) return "Thứ tư";
            if (EntryDate.DayOfWeek == DayOfWeek.Thursday) return "Thứ năm";
            if (EntryDate.DayOfWeek == DayOfWeek.Friday) return "Thứ sáu";
            if (EntryDate.DayOfWeek == DayOfWeek.Saturday) return "Thứ bảy";
            if (EntryDate.DayOfWeek == DayOfWeek.Sunday) return "Chủ nhật";

            return "";
        }


        public static AjaxOut RenderNewsDetail(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {

                string Alias = ORenderInfo.Alias;
                if (ORenderInfo.FromRequest == 1)
                {
                    Alias = WebEnvironments.Request(SiteId, "article");
                }
                if (string.IsNullOrEmpty(Alias)) throw new Exception("Tham số không hợp lệ!");
                string BackAspx = WebEnvironments.Request(SiteId, "BackAspx");

                //GroupDataCls OGroupData = CmsProcessBll.CreateGroupDataModel(SiteId, ORenderInfo.Alias);
                //if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                if (string.IsNullOrEmpty(Alias)) throw new Exception("Chưa xác định Alias cho bài viết Html!");
                CmsDataCls CmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, Alias);
                if (CmsData == null) throw new Exception("Không tìm thấy bài viết. Truy cập không hợp lệ!");
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                string VideoUrl = CmsData.GetAvatarUrl(SiteId, HttpDataRoot);
                if (string.IsNullOrEmpty(ORenderInfo.Title)) ORenderInfo.Title = "News Content";
                string Html =

                     "<div class=cssnewsbody>\r\n" +
                     "<div class=time>Tin đưa ngày: " + GetDayText(CmsData.EntryDate) + ", " + CmsData.EntryDate.ToString("dd/MM/yyyy") + ", " + CmsData.EntryDate.ToString("HH:mm") + " GMT+7</div>\r\n" +
                     "<h3>" + CmsData.Subject + "</h3>\r\n" +
                     "<div class=newscontent>\r\n" +
                                CmsData.Body +
                     "  </div>\r\n" +
                     "  <div class=\"func\"><a href=\"" + GetNewsCategoryUrl(SiteId, CmsData.GroupDataAlias, BackAspx) + "\">Quay lại</a></div>\r\n" +
                     "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        public static AjaxOut RenderMenu(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                CmsDataCls[] CmsData = ReadingServiceBll.ReadingTopListNewsForAlias(SiteId, ORenderInfo.Alias, ORenderInfo.Top, ORenderInfo.ActiveSortIndex);
                string Html =
                    " <ul>";
                for (int iIndex = 0; iIndex < CmsData.Length; iIndex++)
                {
                    CmsDataCls[] CmsSubData = ReadingServiceBll.ReadingTopSubListNewsForAlias(SiteId, CmsData[iIndex].DataId, ORenderInfo.ActiveSortIndex);

                    Html +=
                        " <li class=\"active\"><a href=\"" + CmsData[iIndex].Url + "\">" + CmsData[iIndex].Subject + "</a>\r\n";
                    if (CmsSubData.Length > 0)
                    {
                        Html += "<ul>\r\n";
                        for (int iIndexSub = 0; iIndexSub < CmsSubData.Length; iIndexSub++)
                        {
                            Html +=
                                "   <li><a href=\"" + CmsSubData[iIndexSub].Url + "\">" + CmsSubData[iIndexSub].Subject + "</a></li>\r\n";
                        }
                        Html += "</ul>\r\n";
                    }
                    Html += "</li>\r\n";
                }
                Html +=
                    " </ul> \r\n" +
                    " <div id=\"quicksearch\"> \r\n" +
                    " 	<input type=\"text\" name=\"search_portal\" id=\"search_portal\" class=\"textsearchbox\" value=\"keywords ...\" onblur=\"if(this.value=='') this.value='keywords ...';\" onfocus=\"if(this.value=='keywords ...') this.value='';\" onkeypress=\"javascript:DoPressEnterSearch(event);\" /> \r\n" +
                    "    <a href=\"javascript:void(0);\" onclick =\"javascript:ClientOnSearchClick();\" class=\"searchbut\">search</a> \r\n" +
                    " </div> \r\n";


                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        public static AjaxOut RenderSearchNews(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string k = (string)WebEnvironments.Request(SiteId, "k");
                string fd = (string)WebEnvironments.Request(SiteId, "fd");
                string td = (string)WebEnvironments.Request(SiteId, "td");


                string Html =
                    " <script language=javascript>\r\n" +
                    "   function ClientDoSearchNews()\r\n" +
                    "   {\r\n" +
                    "       Subject=document.getElementById('txtSearchSubject').value;\r\n" +
                    "       FromDate=document.getElementById('txtFromDate').value;\r\n" +
                    "       ToDate=document.getElementById('txtToDate').value;\r\n" +
                    "       window.open('" + ORenderInfo.JumpPageAspx + "?k='+Subject+'&fd='+FromDate+'&td='+ToDate,'_self');\r\n" +
                    "   }\r\n" +

                    "   function ClientResetSearchNews()\r\n" +
                    "   {\r\n" +
                    "       document.getElementById('txtSearchSubject').value='';\r\n" +
                    "       document.getElementById('txtFromDate').value='';\r\n" +
                    "       document.getElementById('txtToDate').value='';\r\n" +
                    "   }\r\n" +
                    " </script>\r\n" +
                    " <div style=\"margin-top:20px;margin-bottom:20px;\"></div> \r\n" +
                    " <div class=CssLeftMenu>\r\n" +
                    "     <h3>Tìm kiếm</h3>\r\n" +
                    "     <div>Từ khóa:</div>\r\n" +
                    "     <div><input id=\"txtSearchSubject\" value=\"" + k + "\" type=textbox class=textbox /></div>\r\n" +
                    "     <div>Ngày đưa tin:</div>\r\n" +
                    "     <div>" + Portal.Utility.LookUpUtilities.GenerateLookUpDate("txtFromDate", fd) + "~" + Portal.Utility.LookUpUtilities.GenerateLookUpDate("txtToDate", td) + "</div>\r\n" +
                    "     <div class=search><input type=button class=button onclick=\"javascript:ClientDoSearchNews('" + ORenderInfo.Alias + "');\" value=\"Tìm kiếm tin\" style=\"margin-right:5px;\"/><input type=button class=button onclick=\"javascript:ClientResetSearchNews();\" value=\"Xóa điều kiện\" style=\"margin-right:22px;\"/></div>\r\n" +
                    " </div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        public static AjaxOut RenderSearchDocument(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {

                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);

                string documentno = (string)WebEnvironments.Request(SiteId, "documentno");
                if (documentno == null) documentno = "";

                string Subject = (string)WebEnvironments.Request(SiteId, "Subject");
                if (Subject == null) Subject = "";

                string sfd = (string)WebEnvironments.Request(SiteId, "sfd");
                if (sfd == null) sfd = "";

                string std = (string)WebEnvironments.Request(SiteId, "std");
                if (std == null) std = "";

                string rfd = (string)WebEnvironments.Request(SiteId, "rfd");
                if (rfd == null) rfd = "";

                string rtd = (string)WebEnvironments.Request(SiteId, "rtd");
                if (rtd == null) rtd = "";

                string efd = (string)WebEnvironments.Request(SiteId, "efd");
                if (efd == null) efd = "";

                string etd = (string)WebEnvironments.Request(SiteId, "etd");
                if (etd == null) etd = "";

                string releasefrom = (string)WebEnvironments.Request(SiteId, "releasefrom");
                if (releasefrom == null) releasefrom = "";

                string docfield = (string)WebEnvironments.Request(SiteId, "docfield");
                if (docfield == null) docfield = "";

                string doctype = (string)WebEnvironments.Request(SiteId, "doctype");
                if (doctype == null) doctype = "";

                string docsigner = (string)WebEnvironments.Request(SiteId, "signer");
                if (docsigner == null) docsigner = "";

                string fulltextsearch = (string)WebEnvironments.Request(SiteId, "fulltextsearch");
                if (string.IsNullOrEmpty(fulltextsearch)) fulltextsearch = "0";

                string fullTextSearchKeyword = (string)WebEnvironments.Request(SiteId, "fullTextSearchKeyword");
                if (string.IsNullOrEmpty(fullTextSearchKeyword)) fullTextSearchKeyword = "";

                string gdf = (string)WebEnvironments.Request(SiteId, "gdf");
                if (string.IsNullOrEmpty(gdf)) gdf = "";

                string status = (string)WebEnvironments.Request(SiteId, "status");
                if (string.IsNullOrEmpty(gdf)) status = "";

                DocReleaseFromCls[] DocReleaseFroms = DocReleaseFromProcessBll.ReadingDocReleaseFrom(SiteId, OGroupData.GroupDataId);
                string SelectReleaseFrom =
                    " <select class=\"drpselect\" id=\"drpDocumentReleasefrom\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocReleaseFroms.Length; iIndex++)
                {
                    if (releasefrom.Equals(DocReleaseFroms[iIndex].DocReleaseFromId))
                    {
                        SelectReleaseFrom += "    <option selected value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + HttpUtility.HtmlEncode(DocReleaseFroms[iIndex].DocReleaseFromName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectReleaseFrom += "    <option value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + HttpUtility.HtmlEncode(DocReleaseFroms[iIndex].DocReleaseFromName) + "</option>\r\n";
                    }
                }

                SelectReleaseFrom +=
                    " </select>\r\n";

                DocSignerCls[] DocSigners = DocSignerProcessBll.ReadingDocSigner(SiteId, OGroupData.GroupDataId);
                string SelectSigner =
                    " <select class=\"drpselect\" id=\"drpDocumentSigner\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocSigners.Length; iIndex++)
                {
                    if (docsigner.Equals(DocSigners[iIndex].DocSignerId))
                    {
                        SelectSigner += "    <option selected value=\"" + DocSigners[iIndex].DocSignerId + "\">" + HttpUtility.HtmlEncode(DocSigners[iIndex].DocSignerName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectSigner += "    <option value=\"" + DocSigners[iIndex].DocSignerId + "\">" + HttpUtility.HtmlEncode(DocSigners[iIndex].DocSignerName) + "</option>\r\n";
                    }
                }
                SelectSigner +=
                    " </select>\r\n";

                string SelectFullText =
                     " <select id=drpSelectFullText class=\"drpselect\" >\r\n" +
                     "  <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                     "  <option value=\"1\">Tìm toàn văn</option>\r\n" +
                     " </select>\r\n";

                if (fulltextsearch.Equals("1"))
                {
                    SelectFullText =
                     " <select id=drpSelectFullText class=\"drpselect\" >\r\n" +
                     "  <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                     "  <option selected value=\"1\">Tìm toàn văn</option>\r\n" +
                     " </select>\r\n";
                }

                string SelectStatus =
                  " <select id=drpSelectStatus class=\"drpselect\" >\r\n" +
                  "  <option selected value=\"\">Toàn bộ</option>\r\n" +
                  "  <option value=\"0\">Hết hiệu lực</option>\r\n" +
                  "  <option value=\"1\">Còn hiệu lực</option>\r\n" +
                  " </select>\r\n";

                if (status.Equals("0"))
                {
                    SelectStatus =
                     " <select id=drpSelectStatus class=\"drpselect\" >\r\n" +
                     "  <option value=\"\">Toàn bộ</option>\r\n" +
                     "  <option selected value=\"0\">Hết hiệu lực</option>\r\n" +
                     "  <option value=\"1\">Còn hiệu lực</option>\r\n" +
                     " </select>\r\n";
                }

                if (status.Equals("1"))
                {
                    SelectStatus =
                     " <select id=drpSelectStatus class=\"drpselect\" >\r\n" +
                     "  <option value=\"\">Toàn bộ</option>\r\n" +
                     "  <option value=\"0\">Hết hiệu lực</option>\r\n" +
                     "  <option selected value=\"1\">Còn hiệu lực</option>\r\n" +
                     " </select>\r\n";
                }

                DocTypeCls[] DocTypes = DocTypeProcessBll.ReadingDocType(SiteId, OGroupData.GroupDataId);
                string SelectDocType =
                    " <select class=\"drpselect\" id=\"drpDocumentDocType\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocTypes.Length; iIndex++)
                {
                    string Url = GetUrlFilters("vi", DocTypes[iIndex].DocTypeName, DocTypes[iIndex].DocTypeId, SiteId, "type");
                    if (doctype.Equals(DocTypes[iIndex].DocTypeId))
                    {
                        SelectDocType += "    <option selected value=\"" + DocTypes[iIndex].DocTypeId + "\">" + HttpUtility.HtmlEncode(DocTypes[iIndex].DocTypeName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectDocType += "    <option value=\"" + DocTypes[iIndex].DocTypeId + "\">" + HttpUtility.HtmlEncode(DocTypes[iIndex].DocTypeName) + "</option>\r\n";
                    }
                }
                SelectDocType +=
                    " </select>\r\n";


                DocFieldCls[] DocFields = DocFieldProcessBll.ReadingDocField(SiteId, OGroupData.GroupDataId);
                string SelectDocField =
                    " <select class=\"drpselect\" id=\"drpDocumentDocField\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocFields.Length; iIndex++)
                {
                    if (docfield.Equals(DocFields[iIndex].DocFieldId))
                    {
                        SelectDocField += "    <option selected value=\"" + DocFields[iIndex].DocFieldId + "\">" + HttpUtility.HtmlEncode(DocFields[iIndex].DocFieldName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectDocField += "    <option value=\"" + DocFields[iIndex].DocFieldId + "\">" + HttpUtility.HtmlEncode(DocFields[iIndex].DocFieldName) + "</option>\r\n";
                    }
                }
                SelectDocField +=
                    " </select>\r\n";

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "divSearchForm");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                string SelectSearchType =
                    "<select id=drpSelectSearchType class=drpselect type=drpselect>\r\n" +
                    "   <option value=\"0\">Tìm toàn từ</option>\r\n" +
                    "   <option value=\"1\">Tìm tách từ</option>\r\n" +
                    "</select>\r\n";

                string stype = (string)WebEnvironments.Request(SiteId, "stype");
                if (string.IsNullOrEmpty(stype)) stype = "0";
                if (stype.Equals("1"))
                {
                    SelectSearchType =
                       "<select id=drpSelectSearchType class=drpselect type=drpselect>\r\n" +
                       "   <option value=\"0\">Tìm toàn từ</option>\r\n" +
                       "   <option selected value=\"1\">Tìm tách từ</option>\r\n" +
                       "</select>\r\n";
                }

                string Html =
                #region javascript
                    " <script language=javascript>\r\n" +
                    "  function CollapseExpandSearchForm(Id)\r\n" +
                    "  {\r\n" +
                    "      SiteId='" + SiteId + "';\r\n" +
                    "      if(document.getElementById(Id).style.display=='block')\r\n" +
                    "      {\r\n" +
                    "          document.getElementById(Id).style.display='none';\r\n" +
                    "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                    "      }\r\n" +
                    "      else\r\n" +
                    "      {\r\n" +
                    "          document.getElementById(Id).style.display='block';\r\n" +
                    "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                    "      }\r\n" +
                    "  }\r\n" +

                    "function encodeUrl(url)\n" +
                    "{\n" +
                    "    if (url.indexOf(\"?\")>0)\n" +
                    "    {\n" +
                    "        encodedParams = \"?\";\n" +
                    "        parts = url.split(\"?\");\n" +
                    "        params = parts[1].split(\"&\");\n" +
                    "        for(i = 0; i < params.length; i++)\n" +
                    "        {\n" +
                    "            if (i > 0)\n" +
                    "            {\n" +
                    "                encodedParams += \"&\";\n" +
                    "            }\n" +
                    "            if (params[i].indexOf(\"=\")>0) //Avoid null values\n" +
                    "            {\n" +
                    "                p = params[i].split(\"=\");\n" +
                    "                encodedParams += (p[0] + \"=\" + escape(encodeURI(p[1])));\n" +
                    "            }\n" +
                    "            else\n" +
                    "            {\n" +
                    "                encodedParams += params[i];\n" +
                    "            }\n" +
                    "        }\n" +
                    "        url = parts[0] + encodedParams;\n" +
                    "    }\n" +
                    "    return url;\n" +
                    "}\n" +

                    "   function ClientDoSearchDocument(PageIndex)\r\n" +
                    "   {\r\n" +
                    "       DocumentNo=document.getElementById('txtDocumentNo').value;\r\n" +
                    "       Subject=document.getElementById('txtDocumentSubject').value;\r\n" +
                    "       SignFromDate='';//document.getElementById('txtSignFromDate').value;\r\n" +
                    "       SignToDate ='';//document.getElementById('txtSignToDate').value;\r\n" +
                    "       ReleaseFromDate=document.getElementById('txtReleaseFromDate').value;\r\n" +
                    "       ReleaseToDate = document.getElementById('txtReleaseToDate').value;\r\n" +
                    "       EffectedFromDate=document.getElementById('txtEffectedFromDate').value;\r\n" +
                    "       EffectedToDate=document.getElementById('txtEffectedToDate').value;\r\n" +
                    "       DocumentReleasefrom=document.getElementById('drpDocumentReleasefrom').value;\r\n" +
                    "       DocumentDocType=document.getElementById('drpDocumentDocType').value;\r\n" +
                    "       DocumentDocField=document.getElementById('drpDocumentDocField').value;\r\n" +
                    "       DocumentSigner=document.getElementById('drpDocumentSigner').value;\r\n" +
                    "       SortField=document.getElementById('drpSelectSortField').value;\r\n" +
                    "       SortType=document.getElementById('drpSortType').value;\r\n" +
                    "       PageSize = document.getElementById('drpSelectPageSize').value;\r\n" +
                    "       fulltextsearch = document.getElementById('chkFullTextSearch').checked;\r\n" +
                    //"       fullTextSearchKeyword = document.getElementById('txtFullTextSearch').value;\r\n" +
                    "       Status=document.getElementById('drpSelectStatus').value;\r\n" +
                    "       SearchType=document.getElementById('chkSearchWord').checked;\r\n" +
                    "       gdf=document.getElementById('txtGroupDataFolderId').value;\r\n" +
                   
                    "       uri=" + ORenderInfo.JumpPageAspx + "?documentno='+DocumentNo+'&subject='+Subject+'&sfd='+SignFromDate+'&std='+SignToDate+'&rfd='+ReleaseFromDate+'&rtd='+ReleaseToDate +'&efd='+EffectedFromDate+'&etd='+EffectedToDate+'&releasefrom='+DocumentReleasefrom+'&signer='+DocumentSigner+'&doctype='+DocumentDocType+'&docfield='+DocumentDocField+'&SortField='+SortField+'&SortType='+SortType+'&PageSize='+PageSize+'&PageIndex='+PageIndex+'&fulltextsearch='+fulltextsearch+'&fullTextSearchKeyword='+fullTextSearchKeyword+'&Status='+Status+'&stype='+SearchType+'&gdf='+gdf,'_self';\r\n" +
                    "       var res = encodeUrl(uri); " +
                    "       window.open(res);\r\n" +
                    //"       window.open('" + ORenderInfo.JumpPageAspx + "?documentno='+DocumentNo+'&subject='+Subject+'&sfd='+SignFromDate+'&std='+SignToDate+'&rfd='+ReleaseFromDate+'&rtd='+ReleaseToDate +'&efd='+EffectedFromDate+'&etd='+EffectedToDate+'&releasefrom='+DocumentReleasefrom+'&signer='+DocumentSigner+'&doctype='+DocumentDocType+'&docfield='+DocumentDocField+'&SortField='+SortField+'&SortType='+SortType+'&PageSize='+PageSize+'&PageIndex='+PageIndex+'&fulltextsearch='+fulltextsearch+'&fullTextSearchKeyword='+fullTextSearchKeyword+'&Status='+Status+'&stype='+SearchType+'&gdf='+gdf,'_self');\r\n" +                    
                    "   }\r\n" +

                    "   function ResetDate(FromId,ToId)\r\n" +
                    "   {\r\n" +
                    "       document.getElementById(FromId).value='';\r\n" +
                    "       document.getElementById(ToId).value='';\r\n" +
                    "   }\r\n" +

                    "   function ClientResetSearch()\r\n" +
                    "   {\r\n" +
                    "       document.getElementById('txtDocumentNo').value='';\r\n" +
                    "       document.getElementById('txtDocumentSubject').value='';\r\n" +
                    //"       document.getElementById('txtSignFromDate').value='';\r\n" +
                    "       document.getElementById('txtSignToDate').value='';\r\n" +
                    "       document.getElementById('txtReleaseFromDate').value='';\r\n" +
                    "       document.getElementById('txtReleaseToDate').value='';\r\n" +
                    "       document.getElementById('txtEffectedFromDate').value='';\r\n" +
                    "       document.getElementById('txtEffectedToDate').value='';\r\n" +
                    "       document.getElementById('drpDocumentReleasefrom').value='';\r\n" +
                    "       document.getElementById('drpDocumentDocType').value='';\r\n" +
                    "       document.getElementById('drpDocumentDocField').value='';\r\n" +
                    "       document.getElementById('drpDocumentSigner').value='';\r\n" +
                    "       document.getElementById('drpSelectSortField').value='';\r\n" +
                    "       document.getElementById('drpSortType').value='';\r\n" +
                    "       document.getElementById('drpSelectPageSize').selectedIndex=0;\r\n" +
                    "       document.getElementById('drpSelectFullText').selectedIndex=0;\r\n" +
                    "       document.getElementById('txtFullTextSearch').value='';\r\n" +
                    "       document.getElementById('drpSelectStatus').selectedIndex=0;\r\n" +
                    "   }\r\n" +
                    " </script> \r\n" +
                #endregion

                    " <input type='hidden' id='txtGroupDataFolderId'  value=\"" + HttpUtility.HtmlEncode(gdf) + "\">\r\n" +
                    " <h3><a href=\"javascript:CollapseExpandSearchForm('divSearchForm');\">Tìm kiếm nâng cao</a></h3> \r\n" +
                    " <div id=\"divSearchForm\" style=\"display:" + DisplayDiv + ";\">\r\n" +
                    " <div class=CssH1>Số văn bản:</div> \r\n" +
                    " <div><input type=textbox class=textbox id=txtDocumentNo value=\"" + HttpUtility.HtmlEncode(documentno) + "\" /></div> \r\n" +
                    " <div class=CssH1>Tiêu đề / mô tả:</div> \r\n" +
                    " <div><input type=textbox class=textbox id=\"txtDocumentSubject\" value=\"" + HttpUtility.HtmlEncode(Subject) + "\" /></div> \r\n" +
                    " <div class=CssH1>Kiểu từ:</div> \r\n" +
                    " <div>" + SelectSearchType + "</div> \r\n" +
                    //" <div class=CssH1>Ngày ký:</div> \r\n" +
                    //" <div>" + LookUpUtilities.GenerateLookUpDate("txtSignFromDate", sfd) + "~" + LookUpUtilities.GenerateLookUpDate("txtSignToDate", std) + "<input style=\"margin-left:5px;\" type=button class=button value=\"Xóa\" onclick=\"javascript:ResetDate('txtSignFromDate','txtSignToDate');\"></div> \r\n" +
                    " <div class=CssH1>Ngày ban hành:</div> \r\n" +
                    " <div>" + LookUpUtilities.GenerateLookUpDate("txtReleaseFromDate", rfd) + "~" + LookUpUtilities.GenerateLookUpDate("txtReleaseToDate", rtd) + "<input style=\"margin-left:5px;\" type=button class=button value=\"Xóa\" onclick=\"javascript:ResetDate('txtReleaseFromDate','txtReleaseToDate');\"></div> \r\n" +
                    " <div class=CssH1>Ngày hiệu lực:</div> \r\n" +
                    " <div>" + LookUpUtilities.GenerateLookUpDate("txtEffectedFromDate", efd) + "~" + LookUpUtilities.GenerateLookUpDate("txtEffectedToDate", etd) + "<input style=\"margin-left:5px;\" type=button class=button value=\"Xóa\"  onclick=\"javascript:ResetDate('txtEffectedFromDate','txtEffectedToDate');\"></div> \r\n" +

                    " <div class=CssH1>Loại văn bản:</div> \r\n" +
                    " <div>" + SelectDocType + "</div> \r\n" +

                    " <div class=CssH1>Lĩnh vực:</div> \r\n" +
                    " <div>" + SelectDocField + "</div> \r\n" +

                    " <div class=CssH1>Cơ quan ban hành:</div> \r\n" +
                    " <div>" + SelectReleaseFrom + "</div> \r\n" +

                    " <div class=CssH1>Người ký:</div> \r\n" +
                    " <div>" + SelectSigner + "</div> \r\n" +

                    " <div class=CssH1>Trạng thái:</div> \r\n" +
                    " <div>" + SelectStatus + "</div> \r\n" +

                    " <div class=CssH1>Toàn văn:</div> \r\n" +
                    " <div>" + SelectFullText + "</div> \r\n" +

                    " <div class=CssH1>Từ khóa toàn văn:</div> \r\n" +
                    " <div><input type=textbox class=textbox id=\"txtFullTextSearch\" value=\"" + HttpUtility.HtmlEncode(fullTextSearchKeyword) + "\" /></div> \r\n" +

                    " <div class=search><input type=button class=button value=\"Xóa điều kiện\" onclick=\"javascript:ClientResetSearch();\"><input type=button class=button value=\"Tìm kiếm văn bản\" onclick=\"javascript:ClientDoSearchDocument(0);\"></div> \r\n" +
                    " </div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderDocumentTypeFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string doctype = (string)WebEnvironments.Request(SiteId, "doctype");
                if (doctype == null) doctype = "";


                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterDocumentType");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "block";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocTypeCls[] DocTypes = DocTypeProcessBll.ReadingDocType(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandDocumentType(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandDocumentType('ulFilterDocumentType');\">Loại văn bản</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterDocumentType style=\"display:" + DisplayDiv + "\">\r\n";

                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string Url = "";
                for (int iIndex = 0; iIndex < DocTypes.Length; iIndex++)
                {
                    Url = GetUrlFilters("vi", DocTypes[iIndex].DocTypeName, DocTypes[iIndex].DocTypeId, SiteId, "type");
                    if (doctype.Equals(DocTypes[iIndex].DocTypeId))
                    {
                        Html += "   <li class=active><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(DocTypes[iIndex].DocTypeName) + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(DocTypes[iIndex].DocTypeName) + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        /// <summary>
        /// Loc theo khoang thoi gian
        /// </summary>
        /// <param name="SiteId"></param>
        /// <param name="ORenderInfo"></param>
        /// <returns></returns>
        public static AjaxOut RenderDocYearRangeFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string YearRange = (string)WebEnvironments.Request(SiteId, "YearRange");
                if (YearRange == null) YearRange = "";


                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterYearRange");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "block";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocYearRangeCls[] YearRanges = DocYearRangeProcessBll.ReadingDocYearRange(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandYearRange(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandYearRange('ulFilterYearRange');\">Năm ban hành</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterYearRange style=\"display:" + DisplayDiv + "\">\r\n";

                string Url = "";

                for (int iIndex = 0; iIndex < YearRanges.Length; iIndex++)
                {
                    Url = GetUrlFilters("vi", YearRanges[iIndex].DocYearRangeName, YearRanges[iIndex].DocYearRangeId, SiteId, "year");

                    if (YearRange.Equals(YearRanges[iIndex].DocYearRangeId))
                    {
                        Html += "   <li class=active><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(YearRanges[iIndex].DocYearRangeName) + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(YearRanges[iIndex].DocYearRangeName) + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }
        /// <summary>
        /// Loc theo nguoi ky
        /// </summary>
        /// <param name="SiteId"></param>
        /// <param name="ORenderInfo"></param>
        /// <returns></returns>
        public static AjaxOut RenderSignerFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string Signer = (string)WebEnvironments.Request(SiteId, "Signer");
                if (Signer == null) Signer = "";

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterSigner");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocSignerCls[] Signers = DocSignerProcessBll.ReadingDocSigner(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandSigner(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandSigner('ulFilterSigner');\">Người ký</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterSigner style=\"display:" + DisplayDiv + "\">\r\n";
                for (int iIndex = 0; iIndex < Signers.Length; iIndex++)
                {
                    if (Signer.Equals(Signers[iIndex].DocSignerId))
                    {
                        Html += "   <li class=active><a href=\"" + ORenderInfo.JumpPageAspx + "?signer=" + Signers[iIndex].DocSignerId + "\">" + Signers[iIndex].DocSignerName + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + ORenderInfo.JumpPageAspx + "?signer=" + Signers[iIndex].DocSignerId + "\">" + Signers[iIndex].DocSignerName + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        /// <summary>
        /// Loc theo co quan ban hanh
        /// </summary>
        /// <param name="SiteId"></param>
        /// <param name="ORenderInfo"></param>
        /// <returns></returns>
        public static AjaxOut RenderDocReleaseFromFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string ReleaseFrom = (string)WebEnvironments.Request(SiteId, "ReleaseFrom");
                if (ReleaseFrom == null) ReleaseFrom = "";

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterReleaseFrom");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocReleaseFromCls[] ReleaseFroms = DocReleaseFromProcessBll.ReadingDocReleaseFrom(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandReleaseFrom(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandReleaseFrom('ulFilterReleaseFrom');\">Cơ quan ban hành</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterReleaseFrom style=\"display:" + DisplayDiv + "\">\r\n";

                string Url = "";
                for (int iIndex = 0; iIndex < ReleaseFroms.Length; iIndex++)
                {
                    Url = GetUrlFilters("vi", ReleaseFroms[iIndex].DocReleaseFromName, ReleaseFroms[iIndex].DocReleaseFromId, SiteId, "rforg");
                    if (ReleaseFrom.Equals(ReleaseFroms[iIndex].DocReleaseFromId))
                    {
                        Html += "   <li class=active><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(ReleaseFroms[iIndex].DocReleaseFromName) + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(ReleaseFroms[iIndex].DocReleaseFromName) + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        /// <summary>
        /// Loc theo Linh vuc van ban
        /// </summary>
        /// <param name="SiteId"></param>
        /// <param name="ORenderInfo"></param>
        /// <returns></returns>
        public static AjaxOut RenderDocFieldFilter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);
                string DocField = (string)WebEnvironments.Request(SiteId, "DocField");
                if (DocField == null) DocField = "";
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "ulFilterDocField");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DocFieldCls[] DocFields = DocFieldProcessBll.ReadingDocField(SiteId, OGroupData.GroupDataId);
                string Html =
                     "<script language=javascript>\r\n" +
                     "  function CollapseExpandDocField(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          SiteId='" + SiteId + "';\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +
                     "</script>\r\n" +
                     "<h3><a href=\"javascript:CollapseExpandDocField('ulFilterDocField');\">Lĩnh vực</a></h3>\r\n" +
                     "<ul class=ulFilter id=ulFilterDocField style=\"display:" + DisplayDiv + "\">\r\n";

                for (int iIndex = 0; iIndex < DocFields.Length; iIndex++)
                {
                    string Url = GetUrlFilters("vi", DocFields[iIndex].DocFieldName, DocFields[iIndex].DocFieldId, SiteId, "field");
                    if (DocField.Equals(DocFields[iIndex].DocFieldId))
                    {
                        Html += "   <li class=active><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(DocFields[iIndex].DocFieldName) + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += "   <li><a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(DocFields[iIndex].DocFieldName) + "</a></li>\r\n";
                    }
                }
                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        class SortFieldCls
        {
            public string Field;
            public string Name;

            public SortFieldCls(string _Field, string _Name)
            {
                Field = _Field;
                Name = _Name;
            }
        }

        class SortSizeCls
        {
            public string Field;
            public string Name;

            public SortSizeCls(string _Field, string _Name)
            {
                Field = _Field;
                Name = _Name;
            }
        }



        public static AjaxOut RenderAdvanceSearchForm(string SiteId, RenderInfoCls ORenderInfo,
            ref string documentno,
            ref string Subject,
            ref string sfd,
            ref string std,
            ref string rfd,
            ref string rtd,
            ref string efd,
            ref string etd,
            ref string releasefrom,
            ref string docfield,
            ref string doctype,
            ref string docsigner,
            ref string gdf,
            ref string status
            )
        {
            AjaxOut OAjaxOut = new AjaxOut();
            string Alias = ORenderInfo.Alias;
            try
            {
                if (string.IsNullOrEmpty(Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + Alias);

                documentno = WebEnvironments.Request(SiteId, "documentno");
                if (!SBVConst.Validator(documentno))
                {
                    documentno = "";
                }

                Subject = WebEnvironments.Request(SiteId, "Subject");
                if (!SBVConst.Validator(Subject))
                    Subject = "";

                sfd = WebEnvironments.Request(SiteId, "sfd");
                if (!SBVConst.Validator(sfd))
                {
                    sfd = "";
                }

                std = WebEnvironments.Request(SiteId, "std");
                if (!SBVConst.Validator(std))
                {
                    std = "";
                }

                rfd = WebEnvironments.Request(SiteId, "rfd");
                if (!SBVConst.Validator(rfd))
                {
                    rfd = "";
                }

                rtd = WebEnvironments.Request(SiteId, "rtd");
                if (!SBVConst.Validator(rtd))
                {
                    rtd = "";
                }

                efd = WebEnvironments.Request(SiteId, "efd");
                if (!SBVConst.Validator(efd))
                {
                    efd = "";
                }

                etd = WebEnvironments.Request(SiteId, "etd");
                if (!SBVConst.Validator(etd))
                {
                    etd = "";
                }

                releasefrom = WebEnvironments.Request(SiteId, "releasefrom");
                if (!SBVConst.Validator(releasefrom))
                {
                    releasefrom = "";
                }

                docfield = WebEnvironments.Request(SiteId, "docfield");
                if (!SBVConst.Validator(docfield))
                {
                    docfield = "";
                }

                doctype = WebEnvironments.Request(SiteId, "doctype");
                if (!SBVConst.Validator(doctype))
                {
                    doctype = "";
                }

                docsigner = WebEnvironments.Request(SiteId, "signer");
                if (!SBVConst.Validator(docsigner))
                {
                    docsigner = "";
                }

                gdf = WebEnvironments.Request(SiteId, "gdf");
                if (!SBVConst.Validator(gdf))
                {
                    gdf = "";
                }

                status = WebEnvironments.Request(SiteId, "Status");
                if (!SBVConst.Validator(status))
                {
                    status = "";
                }


                bool fulltextsearch = false;

                //try
                //{
                //    fulltextsearch = bool.Parse((string)WebEnvironments.Request(SiteId, "fulltextsearch"));
                //}
                //catch
                //{
                //    fulltextsearch = false;
                //}

                //string Docstatus = string.Empty;
                //try
                //{
                //    Docstatus = (string)WebEnvironments.Request(SiteId, "Status");
                //}
                //catch
                //{
                //    Docstatus = string.Empty;
                //}


                if (!string.IsNullOrEmpty(rfd))
                {
                    if (FunctionUtilities.checkVnDate(rfd) == false) throw new Exception("Ngày ban hành không hợp lệ!");
                }
                if (!string.IsNullOrEmpty(rtd))
                {
                    if (FunctionUtilities.checkVnDate(rtd) == false) throw new Exception("Ngày ban hành không hợp lệ!");
                }

                if (!string.IsNullOrEmpty(efd))
                {
                    if (FunctionUtilities.checkVnDate(efd) == false) throw new Exception("Ngày hiệu lực không hợp lệ!");
                }
                if (!string.IsNullOrEmpty(etd))
                {
                    if (FunctionUtilities.checkVnDate(etd) == false) throw new Exception("Ngày hiệu lực không hợp lệ!");
                }
                if (!string.IsNullOrEmpty(documentno))
                {
                    if (documentno.Contains("<scipt>") || documentno.Contains("alert(") || documentno.Contains("return")) if (FunctionUtilities.checkVnDate(etd) == false) throw new Exception("Dữ liệu Số văn bản không hợp lệ!");

                }
                if (!string.IsNullOrEmpty(Subject))
                {
                    if (Subject.Contains("<scipt>") || Subject.Contains("alert(") || Subject.Contains("return")) if (FunctionUtilities.checkVnDate(etd) == false) throw new Exception("Dữ liệu tìm kiếm không hợp lệ!");
                }

                DocReleaseFromCls[] DocReleaseFroms = DocReleaseFromProcessBll.ReadingDocReleaseFrom(SiteId, OGroupData.GroupDataId);
                string SelectReleaseFrom =
                    " <select class=\"drpselect\" id=\"drpDocumentReleasefrom\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocReleaseFroms.Length; iIndex++)
                {
                    if (releasefrom.Equals(DocReleaseFroms[iIndex].DocReleaseFromId))
                    {
                        SelectReleaseFrom += "    <option selected value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + HttpUtility.HtmlEncode(DocReleaseFroms[iIndex].DocReleaseFromName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectReleaseFrom += "    <option value=\"" + DocReleaseFroms[iIndex].DocReleaseFromId + "\">" + HttpUtility.HtmlEncode(DocReleaseFroms[iIndex].DocReleaseFromName) + "</option>\r\n";
                    }
                }
                SelectReleaseFrom +=
                    " </select>\r\n";

                DocSignerCls[] DocSigners = DocSignerProcessBll.ReadingDocSigner(SiteId, OGroupData.GroupDataId);
                string SelectSigner =
                    " <select class=\"drpselect\" id=\"drpDocumentSigner\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocSigners.Length; iIndex++)
                {
                    if (docsigner.Equals(DocSigners[iIndex].DocSignerId))
                    {
                        SelectSigner += "    <option selected value=\"" + DocSigners[iIndex].DocSignerId + "\">" + HttpUtility.HtmlEncode(DocSigners[iIndex].DocSignerName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectSigner += "    <option value=\"" + DocSigners[iIndex].DocSignerId + "\">" + HttpUtility.HtmlEncode(DocSigners[iIndex].DocSignerName) + "</option>\r\n";
                    }
                }
                SelectSigner +=
                    " </select>\r\n";

                //string SelectFullText =
                //     " <select id=drpSelectFullText class=\"drpselect\" >\r\n" +
                //     "  <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                //     "  <option value=\"1\">Tìm toàn văn</option>\r\n" +
                //     " </select>\r\n";

                //if (fulltextsearch.Equals("1"))
                //{
                //    SelectFullText =
                //     " <select id=drpSelectFullText class=\"drpselect\" >\r\n" +
                //     "  <option value=\"0\">Không tìm toàn văn</option>\r\n" +
                //     "  <option selected value=\"1\">Tìm toàn văn</option>\r\n" +
                //     " </select>\r\n";
                //}

                //string status = (string)WebEnvironments.Request(SiteId, "status");
                //if (status == null) status = "";

                string SelectStatus =
                  " <select id=drpSelectStatus class=\"drpselect\" >\r\n" +
                  "  <option selected value=\"\">Toàn bộ</option>\r\n" +
                  "  <option value=\"0\">Hết hiệu lực</option>\r\n" +
                  "  <option value=\"1\">Còn hiệu lực</option>\r\n" +
                  " </select>\r\n";

                if (status.Equals("0"))
                {
                    SelectStatus =
                     " <select id=drpSelectStatus class=\"drpselect\" >\r\n" +
                     "  <option value=\"\">Toàn bộ</option>\r\n" +
                     "  <option selected value=\"0\">Hết hiệu lực</option>\r\n" +
                     "  <option value=\"1\">Còn hiệu lực</option>\r\n" +
                     " </select>\r\n";
                }

                if (status.Equals("1"))
                {
                    SelectStatus =
                     " <select id=drpSelectStatus class=\"drpselect\" >\r\n" +
                     "  <option value=\"\">Toàn bộ</option>\r\n" +
                     "  <option value=\"0\">Hết hiệu lực</option>\r\n" +
                     "  <option selected value=\"1\">Còn hiệu lực</option>\r\n" +
                     " </select>\r\n";
                }


                DocTypeCls[] DocTypes = DocTypeProcessBll.ReadingDocType(SiteId, OGroupData.GroupDataId);
                string SelectDocType =
                    " <select class=\"drpselect\" id=\"drpDocumentDocType\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocTypes.Length; iIndex++)
                {
                    if (doctype.Equals(DocTypes[iIndex].DocTypeId))
                    {
                        SelectDocType += "    <option selected value=\"" + DocTypes[iIndex].DocTypeId + "\">" + HttpUtility.HtmlEncode(DocTypes[iIndex].DocTypeName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectDocType += "    <option value=\"" + DocTypes[iIndex].DocTypeId + "\">" + HttpUtility.HtmlEncode(DocTypes[iIndex].DocTypeName) + "</option>\r\n";
                    }
                }
                SelectDocType +=
                    " </select>\r\n";


                DocFieldCls[] DocFields = DocFieldProcessBll.ReadingDocField(SiteId, OGroupData.GroupDataId);
                string SelectDocField =
                    " <select class=\"drpselect\" id=\"drpDocumentDocField\">\r\n" +
                    "   <option value=\"\">Toàn bộ</option>\r\n";
                for (int iIndex = 0; iIndex < DocFields.Length; iIndex++)
                {
                    if (docfield.Equals(DocFields[iIndex].DocFieldId))
                    {
                        SelectDocField += "    <option selected value=\"" + DocFields[iIndex].DocFieldId + "\">" + HttpUtility.HtmlEncode(DocFields[iIndex].DocFieldName) + "</option>\r\n";
                    }
                    else
                    {
                        SelectDocField += "    <option value=\"" + DocFields[iIndex].DocFieldId + "\">" + HttpUtility.HtmlEncode(DocFields[iIndex].DocFieldName) + "</option>\r\n";
                    }
                }
                SelectDocField +=
                    " </select>\r\n";

                object DisplayDiv = WebSessionUtility.GetSession(SiteId, "divSearchForm");
                if (DisplayDiv == null)
                {
                    DisplayDiv = "none";
                }
                else
                {
                    if ((bool)DisplayDiv)
                    {
                        DisplayDiv = "block";
                    }
                    else
                    {
                        DisplayDiv = "none";
                    }
                }

                DisplayDiv = "none";
                //string SelectSearchType =
                //"<select id=drpSelectSearchType class=drpselect type=drpselect>\r\n" +
                //"   <option value=\"0\">Tìm toàn từ</option>\r\n" +
                //"   <option value=\"1\">Tìm tách từ</option>\r\n" +
                //"</select>\r\n";

                bool stype = false;
                try
                {
                    string wType = WebEnvironments.Request(SiteId, "stype");
                    if (SBVConst.Validator(wType))
                    {
                        stype = bool.Parse(wType);
                    }
                }
                catch { }
                //if (string.IsNullOrEmpty(stype)) stype = "";
                //if (stype.Equals("1"))
                //{
                //    SelectSearchType =
                //       "<select id=drpSelectSearchType class=drpselect type=drpselect>\r\n" +
                //       "   <option value=\"0\">Tìm toàn từ</option>\r\n" +
                //       "   <option selected value=\"1\">Tìm tách từ</option>\r\n" +
                //       "</select>\r\n";
                //}
                

                string Html =
                    " <script language=javascript>\r\n" +

                       "function DoDownload(DataId) {\r\n" +
                "   getverifierval =document.getElementById('captcha').value;\r\n" +
                "   if(getverifierval.length == 0){\r\n" +
                "       alert('Mã xác thực không thể rỗng');\r\n" +
                "       document.getElementById('captcha').focus();\r\n" +
                "       return;\r\n" +
                "   } \r\n" +

                "   temp = new String(document.getElementById('dhtn').value.toString());\r\n" +

                "   var getinputVerifier = temp.substring(0, 1) + temp.substring(6, 7) + temp.substring(12, 13) + temp.substring(18, 19) + temp.substring(24, 25) + temp.substring(30, 31);\r\n" +
                "   var getinputCaptcha = new String(document.getElementById('captcha').value);\r\n" +

                "   if (getinputCaptcha.toUpperCase() != getinputVerifier.toUpperCase()) {\r\n" +
                "       alert('Mã xác thực không đúng, xin nhập lại!');\r\n" +
                "       var rebuildCaptcha = Portal.Admin.Screen.Render.LoginRenderBll.ReCreateCaptcha().value;\r\n" +
                "       document.getElementById('divcaptcha').innerHTML = rebuildCaptcha;\r\n" +
                "       document.getElementById('captcha').focus();\r\n" +
                "       return;\r\n" +
                "   }\r\n" +
                "       ClientDownloadAttachFile(DataId); " +
                "   }\r\n" +

                "   function ClientDownloadAttachFile(DataId)\r\n" +
                "   {\r\n" +
                "       SiteId='" + SiteId + "';\r\n" +
                "       AjaxOut = UNBP.VBPQ.RenderService.VBPQWebRenderBll.ServerSideDownloadAttachFile(SiteId,DataId).value;\r\n" +
                "       if(AjaxOut.Error)\r\n" +
                "       {\r\n" +
                "           alert(AjaxOut.InfoMessage);\r\n" +
                "           return;\r\n" +
                "       }\r\n" +
                "       myWindow = window.open(AjaxOut.RetUrl,'_blank');\r\n" +
                "       myWindow.close();\r\n" +
                "   }\r\n" +

                 "   function ClientDownloadAttachFileNew(DataId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       var url =  '/public/sbv/vi/Capchar.aspx?DataId=' + DataId; " +
                    "       var myWindow = window.open(url, '', 'width=400, height=300');    " +
                    "   }\r\n" +

                     "  function CollapseExpandSearchForm(Id)\r\n" +
                     "  {\r\n" +
                     "      SiteId='" + SiteId + "';\r\n" +
                     "      if(document.getElementById(Id).style.display=='block')\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='none';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'false');\r\n" +
                     "      }\r\n" +
                     "      else\r\n" +
                     "      {\r\n" +
                     "          document.getElementById(Id).style.display='block';\r\n" +
                     "          UNBP.VBPQ.RenderService.VBPQWebRenderBll.SetCollapseExpand(SiteId,Id,'true');\r\n" +
                     "      }\r\n" +
                     "  }\r\n" +


                     "function encodeUrl(url)\n" +
                        "{\n" +
                        "    if (url.indexOf(\"?\")>0)\n" +
                        "    {\n" +
                        "        encodedParams = \"?\";\n" +
                        "        parts = url.split(\"?\");\n" +
                        "        params = parts[1].split(\"&\");\n" +
                        "        for(i = 0; i < params.length; i++)\n" +
                        "        {\n" +
                        "            if (i > 0)\n" +
                        "            {\n" +
                        "                encodedParams += \"&\";\n" +
                        "            }\n" +
                        "            if (params[i].indexOf(\"=\")>0) //Avoid null values\n" +
                        "            {\n" +
                        "                p = params[i].split(\"=\");\n" +
                        "                encodedParams += (p[0] + \"=\" + escape(encodeURI(p[1])));\n" +
                        "            }\n" +
                        "            else\n" +
                        "            {\n" +
                        "                encodedParams += params[i];\n" +
                        "            }\n" +
                        "        }\n" +
                        "        url = parts[0] + encodedParams;\n" +
                        "    }\n" +
                        "    return url;\n" +
                        "}\n" +


                    "   function ClientDoSearchDocument(PageIndex)\r\n" +
                    "   {\r\n" +
                    "       DocumentNo=document.getElementById('txtDocumentNo').value;\r\n" +
                    "       Subject=document.getElementById('txtDocumentSubject').value;\r\n" +
                    "       SignFromDate='';//document.getElementById('txtSignFromDate').value;\r\n" +
                    "       SignToDate ='';//document.getElementById('txtSignToDate').value;\r\n" +
                    "       ReleaseFromDate=document.getElementById('txtReleaseFromDate').value;\r\n" +
                    "       ReleaseToDate = document.getElementById('txtReleaseToDate').value;\r\n" +
                    "       EffectedFromDate=document.getElementById('txtEffectedFromDate').value;\r\n" +
                    "       EffectedToDate=document.getElementById('txtEffectedToDate').value;\r\n" +
                    "       DocumentReleasefrom=document.getElementById('drpDocumentReleasefrom').value;\r\n" +
                    "       DocumentDocType=document.getElementById('drpDocumentDocType').value;\r\n" +
                    "       DocumentDocField=document.getElementById('drpDocumentDocField').value;\r\n" +
                    "       DocumentSigner=document.getElementById('drpDocumentSigner').value;\r\n" +
                    //"       SortField=document.getElementById('txtHiddenSortField').value;\r\n" +
                    "       SortField='';//document.getElementById('drpSelectSortField').value;\r\n" +
                    "       if(document.getElementById('drpSelectSortField')!=null)\r\n" +
                    "       {\r\n" +
                    "           SortField=document.getElementById('drpSelectSortField').value;\r\n" +
                    "       }\r\n" +
                    "       SortType=document.getElementById('txtHiddenSortType').value;\r\n" +
                    "       if(document.getElementById('drpSortType')!=null)\r\n" +
                    "       {\r\n" +
                    "           SortType=document.getElementById('drpSortType').value;\r\n" +
                    "       }\r\n" +
                    "       PageSize = document.getElementById('txtHiddenPageSize').value;\r\n" +
                    "       if(document.getElementById('drpSelectPageSize')!=null)\r\n" +
                    "       {\r\n" +
                    "           PageSize=document.getElementById('drpSelectPageSize').value;\r\n" +
                    "       }\r\n" +
                    "       fulltextsearch = document.getElementById('chkFullTextSearch').checked;\r\n" +
                    //"       fullTextSearchKeyword = document.getElementById('txtFullTextSearch').value;\r\n" +
                    "       Status=document.getElementById('drpSelectStatus').value;\r\n" +
                    "       SearchType=document.getElementById('chkSearchWord').checked;\r\n" +
                    "       gdf=document.getElementById('txtGroupDataFolderId').value;\r\n" +
                    "       uri='" + ORenderInfo.JumpPageAspx + "?documentno='+DocumentNo+'&subject='+Subject+'&sfd='+SignFromDate+'&std='+SignToDate+'&rfd='+ReleaseFromDate+'&rtd='+ReleaseToDate +'&efd='+EffectedFromDate+'&etd='+EffectedToDate+'&releasefrom='+DocumentReleasefrom+'&signer='+DocumentSigner+'&doctype='+DocumentDocType+'&docfield='+DocumentDocField+'&SortField='+SortField+'&SortType='+SortType+'&PageSize='+PageSize+'&PageIndex='+PageIndex+'&fulltextsearch='+fulltextsearch+'&Status='+Status+'&stype='+SearchType+'&gdf='+gdf,'_self';\r\n" +
                    //"       var res = encodeURI(uri); " +
                    "       var res = encodeUrl(uri); " +
                    "       window.open(res,'_self');\r\n" +
                    //"       window.open('" + ORenderInfo.JumpPageAspx + "?documentno='+DocumentNo+'&subject='+Subject+'&sfd='+SignFromDate+'&std='+SignToDate+'&rfd='+ReleaseFromDate+'&rtd='+ReleaseToDate +'&efd='+EffectedFromDate+'&etd='+EffectedToDate+'&releasefrom='+DocumentReleasefrom+'&signer='+DocumentSigner+'&doctype='+DocumentDocType+'&docfield='+DocumentDocField+'&SortField='+SortField+'&SortType='+SortType+'&PageSize='+PageSize+'&PageIndex='+PageIndex+'&fulltextsearch='+fulltextsearch+'&Status='+Status+'&stype='+SearchType+'&gdf='+gdf,'_self');\r\n" +
                    "   }\r\n" +

                    "   function ResetDate(FromId,ToId)\r\n" +
                    "   {\r\n" +
                    "       document.getElementById(FromId).value='';\r\n" +
                    "       document.getElementById(ToId).value='';\r\n" +
                    "   }\r\n" +

                    "   function ClientResetSearch()\r\n" +
                    "   {\r\n" +
                    "       document.getElementById('txtDocumentNo').value='';\r\n" +
                    "       document.getElementById('txtDocumentSubject').value='';\r\n" +
                    //"       document.getElementById('txtSignFromDate').value='';\r\n" +
                    "       document.getElementById('txtSignToDate').value='';\r\n" +
                    "       document.getElementById('txtReleaseFromDate').value='';\r\n" +
                    "       document.getElementById('txtReleaseToDate').value='';\r\n" +
                    "       document.getElementById('txtEffectedFromDate').value='';\r\n" +
                    "       document.getElementById('txtEffectedToDate').value='';\r\n" +
                    "       document.getElementById('drpDocumentReleasefrom').value='';\r\n" +
                    "       document.getElementById('drpDocumentDocType').value='';\r\n" +
                    "       document.getElementById('drpDocumentDocField').value='';\r\n" +
                    "       document.getElementById('drpDocumentSigner').value='';\r\n" +
                    "       document.getElementById('drpSelectSortField').value='';\r\n" +
                    "       document.getElementById('drpSortType').value='';\r\n" +
                    "       document.getElementById('drpSelectPageSize').selectedIndex=0;\r\n" +
                    "       document.getElementById('chkSearchWord').checked=false;\r\n" +
                    "       document.getElementById('chkFullTextSearch').checked=false;\r\n" +
                    "       document.getElementById('drpSelectStatus').selectedIndex=0;\r\n" +
                    "   }\r\n" +
                    " </script> \r\n" +
                    " <input id=\"txtGroupDataFolderId\" type='hidden' value=\"" + HttpUtility.HtmlEncode(gdf) + "\">\r\n" +
                    " <h3><a href=\"javascript:CollapseExpandSearchForm('divSearchForm');\">Tìm kiếm nâng cao</a></h3> \r\n" +
                    " <div id=\"divSearchForm\" class=\"CssSearchForm\" style=\"display:" + DisplayDiv + ";\">\r\n" +
                    " <table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td>\r\n" +
                    "           <div class=CssH1>Số văn bản:</div> \r\n" +
                    "           <div><input type=textbox class=textbox id=txtDocumentNo value=\"" + HttpUtility.HtmlEncode(documentno) + "\" /></div> \r\n" +
                    "           <div class=CssH1>Từ khóa tìm kiếm:</div> \r\n" +
                    "           <div><input type=textbox class=textbox id=\"txtDocumentSubject\" value=\"" + HttpUtility.HtmlEncode(Subject) + "\" /></div>\r\n" +
                    "           <div><input type=checkbox id=\"chkSearchWord\" " + (stype ? "CHECKED" : "") + "><span class=CssSearchWord>Tìm tách từ</span><input id=\"chkFullTextSearch\" type=checkbox " + (fulltextsearch ? "CHECKED" : "") + "><span class=CssSearchWord>Tìm toàn văn</span>\r\n" +                    
                    "           <div class=CssH1>Ngày ban hành:</div> \r\n" +
                    "           <div>" + LookUpUtilities.GenerateLookUpDate("txtReleaseFromDate", rfd) + "~" + LookUpUtilities.GenerateLookUpDate("txtReleaseToDate", rtd) + "<input style=\"margin-left:5px;\" type=button class=button value=\"Xóa\" onclick=\"javascript:ResetDate('txtReleaseFromDate','txtReleaseToDate');\"></div> \r\n" +
                    "           <div class=CssH1>Ngày hiệu lực:</div> \r\n" +
                    "           <div>" + LookUpUtilities.GenerateLookUpDate("txtEffectedFromDate", efd) + "~" + LookUpUtilities.GenerateLookUpDate("txtEffectedToDate", etd) + "<input style=\"margin-left:5px;\" type=button class=button value=\"Xóa\"  onclick=\"javascript:ResetDate('txtEffectedFromDate','txtEffectedToDate');\"></div> \r\n" +
                    "       </td>\r\n" +
                    "       <td>\r\n" +
                    "           <div class=CssH1>Loại văn bản:</div> \r\n" +
                    "           <div>" + SelectDocType + "</div> \r\n" +
                    "           <div class=CssH1>Lĩnh vực:</div> \r\n" +
                    "           <div>" + SelectDocField + "</div> \r\n" +
                    "           <div class=CssH1>Cơ quan ban hành:</div> \r\n" +
                    "           <div>" + SelectReleaseFrom + "</div> \r\n" +
                    "           <div class=CssH1>Người ký:</div> \r\n" +
                    "           <div>" + SelectSigner + "</div> \r\n" +
                    "           <div class=CssH1>Trạng thái:</div> \r\n" +
                    "           <div>" + SelectStatus + "</div> \r\n" +
                    //"           <div class=CssH1>Toàn văn:</div> \r\n" +
                    //"           <div>" + SelectFullText + "</div> \r\n" +
                    //"           <div class=CssH1>Từ khóa toàn văn:</div> \r\n" +
                    //"           <div><input type=textbox class=textbox id=\"txtFullTextSearch\" value=\"" + fullTextSearchKeyword + "\" /></div> \r\n" +
                    "       </td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "<div class=search><input type=button class=button value=\"Xóa điều kiện\" onclick=\"javascript:ClientResetSearch();\"><input type=button class=button value=\"Tìm kiếm văn bản\" onclick=\"javascript:ClientDoSearchDocument(0);\"></div> \r\n" +

                    " </div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        /// <summary>
        /// vbnbnew.aspx
        /// </summary>
        /// <param name="SiteId"></param>
        /// <param name="ORenderInfo"></param>
        /// <returns></returns>
        public static AjaxOut RenderSearchDocumentResult(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias)) throw new Exception("Chưa xác định Alias của nhóm tin!");
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null) throw new Exception("Không tìm thấy nhóm dữ liệu mã " + ORenderInfo.Alias);

                SearchParamCls OSearchParam = new SearchParamCls();
                OSearchParam.ActiveGroupData = true;
                OSearchParam.GroupDataId = OGroupData.GroupDataId;

                string sDocumentno = WebEnvironments.Request(SiteId, "documentno");
                if (SBVConst.Validator(sDocumentno))
                {
                    OSearchParam.SearchDocumentNo = sDocumentno.Trim();
                }
                else
                {
                    OSearchParam.SearchDocumentNo = "";
                }

                OSearchParam.ActiveSearchDocumentNo = !string.IsNullOrEmpty(sDocumentno);
                OSearchParam.PublishingStatus = 1;

                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string UniCode = WebConfig.GetConfigFromXml(OSiteParam, "DefaultAssetCode");
                OSearchParam.IndexesToSearch = WebConfig.DataPathRoot(OSiteParam) + "\\DocumentArchives\\" + UniCode + "\\Xml\\Index";
                OSearchParam.IndexesToSearchAttachDoc = WebConfig.DataPathRoot(OSiteParam) + "\\DocumentArchives\\" + UniCode + "\\ArchiveDoc\\Index";


                if (ORenderInfo.IsNew == 1)
                {
                    //doan nay lay danh sach cac van ban moi
                    string[] LimitDocumentNo = VBPQBussinessProcessBll.ReadingDocumentNew(SiteId, OGroupData.GroupDataId);
                    OSearchParam.ActiveIsNew = true;
                    OSearchParam.ActiveLimitDocumentNo = true;
                    OSearchParam.LimitDocumentNo = LimitDocumentNo;
                }

                string wDoctype = WebEnvironments.Request(SiteId, "doctype");
                if (SBVConst.Validator(wDoctype))
                {
                    OSearchParam.SearchDocType = wDoctype.Trim();
                }
                OSearchParam.ActiveSearchDocType = !string.IsNullOrEmpty(wDoctype);

                string wDocfield = WebEnvironments.Request(SiteId, "docfield");
                if (SBVConst.Validator(wDocfield))
                {
                    OSearchParam.SearchDocField = wDocfield.Trim();
                }
                OSearchParam.ActiveSearchDocField = !string.IsNullOrEmpty(wDocfield);

                string wReleasefrom = WebEnvironments.Request(SiteId, "releasefrom");
                if (SBVConst.Validator(wReleasefrom))
                {
                    OSearchParam.SearchDocReleaseFrom = wReleasefrom.Trim();
                }
                OSearchParam.ActiveSearchDocReleaseFrom = !string.IsNullOrEmpty(wReleasefrom);

                string signer = WebEnvironments.Request(SiteId, "signer");
                if (SBVConst.Validator(signer))
                {
                    OSearchParam.SearchDocSigner = signer.Trim();
                }
                OSearchParam.ActiveSearchDocSigner = !string.IsNullOrEmpty(signer);

                string YearRange = WebEnvironments.Request(SiteId, "YearRange");
                string SearchYearRange = string.Empty; ;
                if (SBVConst.Validator(YearRange))
                {
                    SearchYearRange = YearRange;
                }

                if (!string.IsNullOrEmpty(SearchYearRange))
                {
                    DocYearRangeCls ODocYearRange = DocYearRangeProcessBll.CreateDocYearRangeModel(SiteId, SearchYearRange);
                    OSearchParam.ActiveSearchYearRange = true;
                    OSearchParam.SearchYearRangeFrom = ODocYearRange.FromYear.ToString();
                    OSearchParam.SearchYearRangeTo = ODocYearRange.ToYear.ToString();
                }

                string subject = WebEnvironments.Request(SiteId, "subject");
                if (SBVConst.Validator(subject))
                {
                    OSearchParam.SearchSubject = subject.Trim();
                }
                else
                {
                    OSearchParam.SearchSubject = "";
                    string k = (string)WebEnvironments.Request(SiteId, "k");
                    if (!string.IsNullOrEmpty(k))
                    {
                        OSearchParam.SearchSubject = k;
                        OSearchParam.ActiveSearchSubject = true;
                    }
                }
                OSearchParam.ActiveSearchSubject = !string.IsNullOrEmpty(subject);

                string SortField = WebEnvironments.Request(SiteId, "SortField");
                if (SBVConst.Validator(SortField))
                {
                    OSearchParam.SortField = SortField.Trim();
                }
                else
                {
                    OSearchParam.SortField = "DocumentNo";
                }

                string SortType = WebEnvironments.Request(SiteId, "SortType");
                if (SBVConst.Validator(SortType))
                {
                    OSearchParam.SortType = SortType;
                }
                else
                {
                    OSearchParam.SortType = "ASC";
                }

                try
                {
                    OSearchParam.VnFromSignDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "sfd")).ToString("yyyy/MM/dd");
                    OSearchParam.VnToSignDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "std")).ToString("yyyy/MM/dd");
                    OSearchParam.SearchSignDate = !string.IsNullOrEmpty(OSearchParam.VnFromSignDate) && !string.IsNullOrEmpty(OSearchParam.VnToSignDate);
                }
                catch { }

                try
                {
                    OSearchParam.VnFromReleaseDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "rfd")).ToString("yyyy/MM/dd");
                    OSearchParam.VnToReleaseDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "rtd")).ToString("yyyy/MM/dd");
                    OSearchParam.SearchReleaseDate = !string.IsNullOrEmpty(OSearchParam.VnFromReleaseDate) && !string.IsNullOrEmpty(OSearchParam.VnToReleaseDate);
                }
                catch { }

                try
                {
                    OSearchParam.VnFromEffectedDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "efd")).ToString("yyyy/MM/dd");
                    OSearchParam.VnToEffectedDate = FunctionUtilities.VNDateToDate((string)WebEnvironments.Request(SiteId, "etd")).ToString("yyyy/MM/dd");
                    OSearchParam.SearchEffectedDate = !string.IsNullOrEmpty(OSearchParam.VnFromEffectedDate) && !string.IsNullOrEmpty(OSearchParam.VnToEffectedDate);
                }
                catch { }

                try
                {
                    string Status = WebEnvironments.Request(SiteId, "Status");
                    if (SBVConst.Validator(Status))
                    {
                        OSearchParam.Status = int.Parse(Status);
                    }
                }
                catch
                {
                    OSearchParam.Status = 2;
                }

                OSearchParam.PageSize = 10;
                try
                {
                    string PageSize = WebEnvironments.Request(SiteId, "PageSize");
                    if (SBVConst.Validator(PageSize))
                    {
                        OSearchParam.PageSize = int.Parse(PageSize);
                    }
                }
                catch { }


                bool stype = false;
                try
                {
                    string sType = WebEnvironments.Request(SiteId, "stype");
                    if (SBVConst.Validator(sType))
                    {
                        stype = bool.Parse(sType);
                    }
                }
                catch { }

                int PageIndex = 0;
                try
                {
                    string sPageIndex = WebEnvironments.Request(SiteId, "PageIndex");
                    if (SBVConst.Validator(sPageIndex))
                    {
                        PageIndex = int.Parse(sPageIndex);
                    }
                }
                catch { }


                OSearchParam.ActiveSplitSearch = stype;
                OSearchParam.PageIndex = PageIndex;
                OSearchParam.DataRoot = WebConfig.DataPathRoot(OSiteParam);


                //todo: user dtserach
                //fix to sql command
                //SearchResultCls OSearchResult = SearchBll.Execute(SiteId, OSearchParam);
                //WebSessionUtility.GetCurrentLoginUser().
                string sortValue = string.Empty;

                try
                {
                    sortValue = WebEnvironments.Request(SiteId, "SortField");
                    if (SBVConst.Validator(sortValue))
                    {
                        string wSortType = WebEnvironments.Request(SiteId, "SortType");
                        if (SBVConst.Validator(wSortType))
                        {
                            sortValue += " " + wSortType;
                        }
                    }
                }
                catch { sortValue = string.Empty; }

                string documentNo = string.Empty;
                string Subject = string.Empty;
                string sfd = string.Empty;
                string std = string.Empty;
                string rfd = string.Empty;
                string rtd = string.Empty;
                string efd = string.Empty;
                string etd = string.Empty;
                string releaseFrom = string.Empty;
                string docField = string.Empty;
                string docType = string.Empty;
                string docSigner = string.Empty;
                string gdf = string.Empty;
                string status = string.Empty;

                string buildAdvanceSearchForm = RenderAdvanceSearchForm(SiteId, ORenderInfo,
                     ref documentNo,
                     ref Subject,
                     ref sfd,
                     ref std,
                     ref rfd,
                     ref rtd,
                     ref efd,
                     ref etd,
                     ref releaseFrom,
                     ref docField,
                     ref docType,
                     ref docSigner,
                     ref gdf,
                     ref status
                    ).HtmlContent;



                SortFieldCls[] SortFields = new SortFieldCls[]{
                    new SortFieldCls("Subject","Số văn bản"),
                    //new SortFieldCls("Subject","Tiêu đề"),
                    new SortFieldCls("frkDocTypeId","Loại văn bản"),
                    new SortFieldCls("frkDocFieldId","Lĩnh vực"),
                    new SortFieldCls("frkDocReleaseFromId","Cơ quan ban hành"),
                    new SortFieldCls("frkDocSignerId","Người ký"),
                    //new SortFieldCls("SignDate","Ngày ký"),
                    new SortFieldCls("ReleaseDate","Ngày ban hành"),
                    new SortFieldCls("EffectedDate","Ngày hiệu lực"),
                };


                string SelectSortFieldText =
                    "<select id=drpSelectSortField class=drpselect>\r\n";
                for (int iIndex = 0; iIndex < SortFields.Length; iIndex++)
                {
                    if (OSearchParam.SortField.Equals(SortFields[iIndex].Field))
                    {
                        SelectSortFieldText += "  <option selected value=\"" + SortFields[iIndex].Field + "\">" + SortFields[iIndex].Name + "</option>\r\n";
                    }
                    else
                    {
                        SelectSortFieldText += "  <option value=\"" + SortFields[iIndex].Field + "\">" + SortFields[iIndex].Name + "</option>\r\n";
                    }
                }
                SelectSortFieldText += "</select>\r\n";

                SortSizeCls[] SortSize = new SortSizeCls[]{
                    new SortSizeCls("5","05"),
                    new SortSizeCls("10","10"),
                    new SortSizeCls("15","15"),
                    new SortSizeCls("20","20"),
                    new SortSizeCls("25","25"),
                };


                string SelectSortSizeText =
                  "<select id=drpSelectPageSize class=drpselect>\r\n";
                for (int iIndex = 0; iIndex < SortSize.Length; iIndex++)
                {
                    if (OSearchParam.PageSize == int.Parse(SortSize[iIndex].Field))
                    {
                        SelectSortSizeText += "  <option selected value=\"" + SortSize[iIndex].Field + "\">" + SortSize[iIndex].Name + "</option>\r\n";
                    }
                    else
                    {
                        SelectSortSizeText += "  <option value=\"" + SortSize[iIndex].Field + "\">" + SortSize[iIndex].Name + "</option>\r\n";
                    }
                }
                SelectSortSizeText += "</select>\r\n";

                string SelectSortType = " <select id=drpSortType class=drpselect>\r\n" +
                                        "   <option value=\"ASC\">Sắp xếp tăng dần</option>\r\n" +
                                        "   <option value=\"DESC\">Sắp xếp giảm dần</option>\r\n" +
                                        " </select>\r\n";
                if (OSearchParam.SortType.Equals("DESC"))
                {
                    SelectSortType = " <select id=drpSortType class=drpselect>\r\n" +
                                        "   <option value=\"ASC\">Sắp xếp tăng dần</option>\r\n" +
                                        "   <option selected value=\"DESC\">Sắp xếp giảm dần</option>\r\n" +
                                        " </select>\r\n";
                }


                string GroupDataName = OGroupData.GroupDataName;
                if (!string.IsNullOrEmpty(ORenderInfo.Title))
                {
                    GroupDataName = ORenderInfo.Title;
                }

                try
                {
                    string wFullTextSearch = WebEnvironments.Request(SiteId, "fullTextSearch");
                    if (SBVConst.Validator(wFullTextSearch))
                    {
                        OSearchParam.ActiveFullTextSearch = bool.Parse(wFullTextSearch);
                    }
                    if (OSearchParam.ActiveFullTextSearch)
                    {
                        OSearchParam.fullTextSearchKeyword = OSearchParam.SearchSubject;
                    }
                }
                catch
                {
                    OSearchParam.ActiveFullTextSearch = false;
                }


                //111
                CmsDataCls[] OSearchResult = new CmsProcessBll().SearchAdvancePublicCmsData(
                    SiteId,
                    OGroupData.GroupDataId,
                    string.Empty,
                    string.Empty,
                    "1",
                    sortValue,
                    HttpUtility.HtmlEncode(documentNo),
                    HttpUtility.HtmlEncode(Subject),
                    sfd,
                    std,
                    rfd,
                    rtd,
                    efd,
                    etd,
                    releaseFrom,
                    docField,
                    docType,
                    docSigner,
                    gdf,
                    status,
                    OSearchParam.SearchYearRangeFrom,
                    OSearchParam.SearchYearRangeTo

                    );
                //if (OSearchResult.SearchOk == false)
                //{
                //    throw new Exception(OSearchResult.InfoMessage);
                //}
                //VBPQReturnPaging OReturnPaging = VBPQPagingUtilities.GetPaging(OSearchResult.SearchResultItems.Count, PageIndex, OSearchParam.PageSize, 10, "NextPage", 0);
                ReturnPaging OReturnPaging = WebPaging.GetPaging(OSearchResult.Length, PageIndex, OSearchParam.PageSize, 10, "NextPage", 0);

                string PagingText = OReturnPaging.PagingText;// OSearchResult.PaggingText;
                int CountIndex = ((OReturnPaging.StartIndex != 0) ? CountIndex = PageIndex + OSearchParam.PageSize - 1 : OReturnPaging.StartIndex);// OSearchResult.StartIndex;
                string Html =
                    " <input type=hidden id=\"txtHiddenSortType\" value=\"" + HttpUtility.HtmlEncode(OSearchParam.SortType) + "\">\r\n" +
                    " <input type=hidden id=\"txtHiddenSortField\" value=\"" + HttpUtility.HtmlEncode(OSearchParam.SortField) + "\">\r\n" +
                    " <input type=hidden id=\"txtHiddenPageSize\" value=\"" + HttpUtility.HtmlEncode(OSearchParam.PageSize.ToString()) + "\">\r\n" +
                    " <script language=javascript>\r\n" +
                    "   function NextPage(CurrentPageIndex)\r\n" +
                    "   {\r\n" +
                    "       ClientDoSearchDocument(CurrentPageIndex);\r\n" +
                    "   }\r\n" +
                    "   function ClientDownloadAttachFile(DataId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       AjaxOut = UNBP.VBPQ.RenderService.VBPQWebRenderBll.ServerSideDownloadAttachFile(SiteId,DataId).value;\r\n" +
                    "       if(AjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(AjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n" +
                    "       window.open(AjaxOut.RetUrl,'_blank');\r\n" +
                    "   }\r\n" +
                    " </script>\r\n" +

                    " <div class=CssListCategory>\r\n" +
                    " <h3>" + Subject + "</h3>\r\n" +
                        buildAdvanceSearchForm;//RenderAdvanceSearchForm(SiteId, ORenderInfo).HtmlContent;

                if (OSearchResult.Length > 0)
                {
                    Html +=
                        " <div class=CssNewsHeading>Tổng số có " + HttpUtility.HtmlEncode(OSearchResult.Length.ToString()) + " văn bản trong chuyên mục</div>\r\n" +
                        " <div class=CssSort>Sắp xếp: " + SelectSortFieldText + " - Kiểu: " + SelectSortType + " - văn bản " + SelectSortSizeText + " / trang <input type=button class=button value=\"Sắp xếp\" onclick=\"javascript:NextPage(0);\"></div>\r\n";
                }
                else
                {
                    Html +=
                        " <div class=CssRecordNotFound>Không tìm thấy văn bản nào thỏa mãn điều kiện tìm kiếm. Xin vui lòng chọn lại điều kiện</div>\r\n";
                }
                //draw search form
                Html +=
                    PagingText + "<br/>" +
                    " <div class=CssResultItems>\r\n" +
                    " <table> \r\n";
                for (int iIndex = OReturnPaging.StartIndex; iIndex < OReturnPaging.EndIndex; iIndex++)
                {
                    //string ImageFile = "pdf.png";
                    string NewDoc = "";
                    if (OSearchResult[iIndex].IsNew == 1)
                    {
                        NewDoc = " <img class=imgnew src=\"Resources/Images/newred.png\"></img>";
                    }

                    string Url = ORenderInfo.NextJumpPageAspx + "?id=" + OSearchResult[iIndex].DataId + "&back=" + ORenderInfo.JumpPageAspx;
                    try
                    {
                        Url = GetUrlDetails("vi", OSearchResult[iIndex].DocTypeName, OSearchResult[iIndex].DataId, OSiteParam);
                    }
                    catch { }

                    Html +=
                        " <tr> \r\n" +
                        "    <td> \r\n" +
                        //"        <div class=CssDivDocNo><a href=\"" + ORenderInfo.NextJumpPageAspx + "?id=" + OSearchResult[iIndex].DataId + "&back=" + ORenderInfo.JumpPageAspx + "\"><span class=\"DocNo\">" + (CountIndex + 1) + ". " + OSearchResult[iIndex].DocTypeName + " số: " + ProcessHighLight(OSearchParam.SearchDocumentNo, OSearchResult[iIndex].Subject) + " - Ngày ban hành: <span class=CssDate>" + OSearchResult[iIndex].ReleaseDate + "</span></span>" + NewDoc + "</a></div> \r\n" +
                        "        <div class=CssDivDocNo><a href=\"" +  Url + "\"><span class=\"DocNo\">" + (CountIndex + 1) + ". " + HttpUtility.HtmlEncode(OSearchResult[iIndex].DocTypeName) + " số: " + HttpUtility.HtmlEncode(ProcessHighLight(OSearchParam.SearchDocumentNo, OSearchResult[iIndex].Subject)) + " - Ngày ban hành: <span class=CssDate>" + HttpUtility.HtmlEncode(OSearchResult[iIndex].ReleaseDate) + "</span></span>" + NewDoc + "</a></div> \r\n" +
                        "        <div class=CssDocTitle>" + ProcessHighLight(OSearchParam.SearchSubject, HttpUtility.HtmlEncode(OSearchResult[iIndex].Subject)) + "</div> \r\n" +
                        "        <div>Cơ quan ban hành: <span class=ReleaseFrom>" + HttpUtility.HtmlEncode(OSearchResult[iIndex].DocReleaseFromName) + "</span></div> \r\n" +
                        "        <div>Người ký: <span class=ReleaseFrom>" + HttpUtility.HtmlEncode(OSearchResult[iIndex].DocSignerName) + "</span></div> \r\n" +
                        "        <div>Ngày hiệu lực <span class=CssDate>" + HttpUtility.HtmlEncode(OSearchResult[iIndex].EffectedDate) + "</span> - Tình trạng:<span class=CssDate>" + (HttpUtility.HtmlEncode(OSearchResult[iIndex].DocStatus).Equals("1") ? "Còn hiệu lực" : "Hết hiệu lực") + "</span></div> \r\n" +
                        "        <div class=download><img class=image style=\"margin-left:10px;border:none;\" onclick=\"javascript:ClientDownloadAttachFileNew('" + HttpUtility.HtmlEncode(OSearchResult[iIndex].DataId) + "');\" alt=\"Download tài liệu gắn kèm\" title=\"Download tài liệu gắn kèm\" class=image src=\"Resources/Images/download.png\"></div> \r\n" +
                        "   </td> \r\n" +
                        "</tr> \r\n";
                    CountIndex++;
                }
                Html +=
                    "</table>\r\n" +
                    "</div>\r\n" +
                    PagingText + "<br/>" +

                    " <div class=\"clr\"></div>\r\n" +
                    " </div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut ViewDocumentDetail(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string Id = (string)WebEnvironments.Request(SiteId, "Id");
                if (!SBVConst.Validator(Id))
                    throw new Exception("Tài liệu không tìm thấy! Truy vấn không hợp lệ");
                //if (string.IsNullOrEmpty(Id)) throw new Exception("Tài liệu không tìm thấy! Truy vấn không hợp lệ");                

                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, Id, true, false);
                if (OCmsData == null) throw new Exception("Tài liệu không tìm thấy! Truy vấn không hợp lệ");

                string NewDoc = "";
                if (OCmsData.IsNew == 1)
                {
                    NewDoc = " <img class=imgthumb src=\"Resources/Images/newred.png\"></img>";
                }
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                //string PdfViewerUrl = WebConfig.GetConfigFromXml(OSiteParam, "PdfViewerUrl");      
          
                string Html =
                    " <script language=javascript>\r\n" +
                 
                    "   function ClientDownloadAttachFileNew(DataId)\r\n" +
                    "   {\r\n" +                    
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       var url =  '/public/sbv/vi/Capchar.aspx?DataId=' + DataId; "  +
                    "       var myWindow = window.open(url, '', 'width=400, height=300');    " +                    
                    "   }\r\n" +

                    " </script>\r\n" +
                    " <div class=CssListCategory> \r\n" +
                    //" <div class=vTitle>" + OCmsData.Subject + " - <a href=\"" + BackUrl + "\"></div>\r\n" +
                    " <div class=vTitle>" + OCmsData.Subject + "<a href=\"javascript:history.back(-1);\"></div>\r\n" +
                    " <div class=func>Danh sách</a> | <a href=\"javascript:history.back(-1);\">Quay lại</a></div> \r\n" +
                    " <table> \r\n" +
                    "     <tr> \r\n" +
                    "         <td style=\"width:40px;vertical-align:top\">" + NewDoc + "</td> \r\n" +
                    "         <td> \r\n" +
                    "             <div class=viewdetail> \r\n" +
                    "             <table> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Số văn bản:</td> \r\n" +
                    //"                     <td class=col2><span class=\"DocNo\">" + OCmsData.Subject + "</span></td> \r\n" +
                    "                     <td class=col2><span class=\"DocNo\">" + HttpUtility.HtmlEncode(OCmsData.Subject) + "</span></td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Trích yếu:</td> \r\n" +
                    "                     <td class=col2><span class=CssTrichYeuDetail>" + HttpUtility.HtmlEncode(OCmsData.Description) + "</span></td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Lĩnh vực:</td> \r\n" +
                    "                     <td class=col2>" + HttpUtility.HtmlEncode(OCmsData.DocFieldName) + "</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Loại văn bản:</td> \r\n" +
                    "                     <td class=col2>" + HttpUtility.HtmlEncode(OCmsData.DocTypeName) + "</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Đơn vị ban hành:</td> \r\n" +
                    "                     <td class=col2>" + HttpUtility.HtmlEncode(OCmsData.DocReleaseFromName) + "</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Ngày ban hành:</td> \r\n" +
                    "                     <td class=col2><span class=CssDate>" + HttpUtility.HtmlEncode(OCmsData.ReleaseDate) + "</span</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Ngày hiệu lực:</td> \r\n" +
                    "                     <td class=col2><span class=CssDate>" + HttpUtility.HtmlEncode(OCmsData.EffectedDate) + "</span</td> \r\n" +
                    "                 </tr> \r\n" +
                    "                 <tr> \r\n" +
                    "                     <td class=col1>Xem / tải về máy:</td> \r\n" +
                    "                     <td class=col2><div class=download><img onclick=\"javascript:ClientDownloadAttachFileNew('" + OCmsData.DataId + "');\" style=\"border:none;\" alt=\"Download tài liệu gắn kèm\" title=\"Download tài liệu gắn kèm\" class=image src=\"Resources/Images/download.png\"></div></td> \r\n" +
                    "                 </tr> \r\n" +

                    "                 <tr> \r\n" +
                    "                     <td class=col1></td> \r\n" +
                    "                     <td class=col2>Số lần xem: <span class=CssTotalView>" + HttpUtility.HtmlEncode(OCmsData.TotalPreview.ToString("#,##0")) + "</span> | Số lần tải: <span class=CssTotalDownload>" + HttpUtility.HtmlEncode(OCmsData.TotalDownload.ToString("#,##0")) + "</span></td> \r\n" +
                    "                 </tr> \r\n" +

                    "             </table> \r\n" +
                    "             </div> \r\n" +
                    "         </td> \r\n" +
                    "     </tr> \r\n" +
                    "</table> \r\n";
                RelationTypeCls[] RelationTypes = RelationTypeProcessBll.ReadingRelationType(SiteId, OCmsData.frkGroupDataId);
                for (int iIndex = 0; iIndex < RelationTypes.Length; iIndex++)
                {
                    CmsDataRelationCls[] CmsDataRelations = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingDocumentRelation(SiteId, OCmsData.DataId, RelationTypes[iIndex].RelationTypeId);
                    if (CmsDataRelations.Length > 0)
                    {
                        Html +=
                        " <h3>" + RelationTypes[iIndex].RelationTypeName + "</h3>\r\n" +
                        " <div class=relationdoc>\r\n" +
                        " <ul>\r\n";
                        for (int zIndex = 0; zIndex < CmsDataRelations.Length; zIndex++)
                        {
                            Html +=
                                "<li>\r\n" +
                                "    <span class=DocNo>Số: </span> <a href=\"?id=" + CmsDataRelations[zIndex].DataId + ">" + HttpUtility.HtmlEncode(CmsDataRelations[zIndex].Subject) + "</a>\r\n" +
                                "</li>\r\n";
                        }
                        Html +=
                        "</ul>\r\n" +
                        "</div>\r\n";
                    }
                }

                RelationTypes = RelationTypeProcessBll.ReadingRelationTypeOut(SiteId, OCmsData.frkGroupDataId);
                for (int iIndex = 0; iIndex < RelationTypes.Length; iIndex++)
                {
                    CmsDataRelationCls[] CmsDataRelations = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingDocumentRelationOut(SiteId, OCmsData.DataId, RelationTypes[iIndex].RelationTypeId);
                    if (CmsDataRelations.Length > 0)
                    {
                        Html +=
                        " <h3>" + RelationTypes[iIndex].RelationTypeName.ToLower() + "</h3>\r\n" +
                        " <div class=relationdoc>\r\n" +
                        " <ul>\r\n";
                        for (int zIndex = 0; zIndex < CmsDataRelations.Length; zIndex++)
                        {
                            string Url = ORenderInfo.NextJumpPageAspx + "?id=" + CmsDataRelations[zIndex].DataId;
                            try
                            {
                                Url = GetUrlDetails("vi", HttpUtility.HtmlEncode(CmsDataRelations[zIndex].Subject), CmsDataRelations[zIndex].DataId, OSiteParam);
                            }
                            catch { }
                            Html +=
                                "<li>\r\n" +
                                "    <span class=DocNo>Số: <a href=\"" + Url + "\">" + HttpUtility.HtmlEncode(CmsDataRelations[zIndex].Subject) + "</a></span>\r\n" +
                                //"    <span class=DocNo>Số: <a href=\"?id=" + CmsDataRelations[zIndex].DataId + "\">" + HttpUtility.HtmlEncode(CmsDataRelations[zIndex].Subject) + "</a></span>\r\n" +
                                "</li>\r\n";
                        }
                        Html +=
                        "</ul>\r\n" +
                        "</div>\r\n";
                    }
                }

                Html +=
                   " <div class=\"clr\"></div>\r\n" +
                   " </div>";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDownloadAttachFile(string SiteId, string DataId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, DataId, false, true);
                //string AttachDocFile=OCmsData.GetAttachDocFile(SiteId);
                //string PathSave=Environments.DataPathRoot(SiteId) + "\\temp";
                //System.IO.Directory.CreateDirectory(PathSave);
                //PathSave = PathSave + "\\" + OCmsData.UniCode;
                //System.IO.Directory.CreateDirectory(PathSave);
                //string tempFile = PathSave + "\\" + new System.IO.FileInfo(AttachDocFile).Name;
                //try
                //{
                //    if (System.IO.File.Exists(tempFile) == false)
                //    {
                //        System.IO.File.Copy(AttachDocFile, tempFile, true);
                //    }
                //}
                //catch { }
                //OAjaxOut.RetUrl = Environments.DataPathRoot(SiteId) + "/temp/" + OCmsData.UniCode + "/" + new System.IO.FileInfo(AttachDocFile).Name;
                //CmsProcessBll.UpdateTotalDownload(SiteId, DataId);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string HttpDataRoot = WebConfig.HttpDataRoot(OSiteParam);
                OAjaxOut.RetUrl = OCmsData.GetAttachDocUrl(SiteId, HttpDataRoot);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static void SetCollapseExpand(string SiteId, string DivId, string Expand)
        {
            WebSessionUtility.SetSession(SiteId, DivId, bool.Parse(Expand));
        }

        static string ProcessHighLight(string SearchSubject, string Subject)
        {
            if (string.IsNullOrEmpty(SearchSubject))
            {
                return Subject;
            }
            else
            {
                string ReturnSubject = Subject;
                string[] Items = SearchSubject.Split(new char[] { '%' }, StringSplitOptions.RemoveEmptyEntries);
                for (int iIndex = 0; iIndex < Items.Length; iIndex++)
                {
                    int iFound = Subject.ToLower().IndexOf(Items[iIndex].ToLower());
                    if (iFound != -1)
                    {
                        string Keyword = ReturnSubject.Substring(iFound, Items[iIndex].Length);
                        string SpanLink = "<span style=\"background-color:yellow;color:maroon;padding:2px;\">" + Keyword + "</span>";
                        ReturnSubject = ReturnSubject.Substring(0, iFound) + SpanLink + ReturnSubject.Substring(iFound + Items[iIndex].Length);
                    }
                    //Subject = Subject.Replace(Items[iIndex], "");
                }
                return ReturnSubject;
            }
        }




        public static AjaxOut RenderOtherNews(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias))
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                CmsDataCls OCmsData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateCmsDataModel(null, SiteId, ORenderInfo.Alias);
                if (OCmsData == null)
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                CmsDataCls[] OtherNews = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingCmsDataIsPublicExclusive(SiteId, OCmsData.frkGroupDataId, OCmsData.DataId, 20);
                string Html =
                    "<h3>Các tin khác</h3>\r\n" +
                    "<ul>\r\n";
                for (int iIndex = 0; iIndex < OtherNews.Length; iIndex++)
                {
                    Html += " <li><a href=\"newsdetail.aspx?article=" + OtherNews[iIndex].DataId + "&backaspx=" + ORenderInfo.JumpPageAspx + "\">" + OtherNews[iIndex].Subject + "</li>\r\n";
                }
                Html +=
                    "</ul>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        public static AjaxOut RenderMenuBar(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias))
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null)
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                CmsDataCls[] MenuItems = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingCmsDataIsPublic(SiteId, OGroupData.GroupDataId, null);
                string Html =
                    "<script language=javascript>\r\n" +
                    "   function doSimpleSearch()\r\n" +
                    "   {\r\n" +
                    "           Keyword = document.getElementById(\"txtQuickKeyword\").value;\r\n" +
                    "           if(Keyword.trim().length==0)\r\n" +
                    "           {\r\n" +
                    "               alert('Từ khóa tìm kiếm chưa nhập hoặc không hợp lệ!');\r\n" +
                    //"               tb.selectAll();\r\n"+
                    "               document.getElementById(\"txtQuickKeyword\").focus();\r\n" +
                    "           }\r\n" +
                    "           else\r\n" +
                    "           {\r\n" +
                    "               window.open('" + HttpUtility.HtmlEncode(ORenderInfo.JumpPageAspx) + "?k='+Keyword,'_self');\r\n" +
                    "           }\r\n" +
                    "   }\r\n" +

                    "   function ScriptKeyWordPress(e)\r\n" +
                    "   {\r\n" +
                    "       if (e.keyCode == 13) {\r\n" +
                    "           doSimpleSearch();\r\n" +
                    "           return false;\r\n" +
                    "       }\r\n" +
                    "   }\r\n" +
                    "</script>\r\n" +

                    "<ul>\r\n";
                for (int iIndex = 0; iIndex < MenuItems.Length; iIndex++)
                {
                    if (MenuItems[iIndex].DataAlias.Equals(ORenderInfo.Active))
                    {
                        Html += " <li id=\"current\"><a href=\"" + MenuItems[iIndex].Url + "\">" + HttpUtility.HtmlEncode(MenuItems[iIndex].Subject) + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += " <li><a href=\"" + MenuItems[iIndex].Url + "\">" + HttpUtility.HtmlEncode(MenuItems[iIndex].Subject) + "</a></li>\r\n";
                    }
                }
                string k = (string)WebEnvironments.Request(SiteId, "k");
                Html +=
                    "</ul>\r\n" +
                    "<div class=CssDivSearch><a>Từ khóa:</a> <input onkeypress=\"return ScriptKeyWordPress(event)\" class=textbox type=textbox id=txtQuickKeyword value=\"" + k + "\"><a class=CssButtonSimpleSearch href=\"javascript:doSimpleSearch();\">Tìm</a></div>\r\n";

                if (!string.IsNullOrEmpty(k))
                {
                    Html += "<script language=javascript>\r\n" +
                            "   document.getElementById(\"txtQuickKeyword\").focus();\r\n" +
                            "</script>\r\n";
                }
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        public static AjaxOut RenderMenuBarBottom(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias))
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null)
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                CmsDataCls[] MenuItems = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingCmsDataIsPublic(SiteId, OGroupData.GroupDataId, null);
                string Html =
                    "<ul>\r\n";
                for (int iIndex = 0; iIndex < MenuItems.Length; iIndex++)
                {
                    if (MenuItems[iIndex].DataAlias.ToLower().Equals("footer"))
                        continue;
                    if (MenuItems[iIndex].DataAlias.Equals(ORenderInfo.Active))
                    {
                        Html += " <li id=\"current\"><a href=\"" + MenuItems[iIndex].Url + "\">" + HttpUtility.HtmlEncode(MenuItems[iIndex].Subject) + "</a></li>\r\n";
                    }
                    else
                    {
                        Html += " <li><a href=\"" + MenuItems[iIndex].Url + "\">" + HttpUtility.HtmlEncode(MenuItems[iIndex].Subject) + "</a></li>\r\n";
                    }
                }
                string k = (string)WebEnvironments.Request(SiteId, "k");
                Html +=
                    "</ul>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        public static AjaxOut RenderFooter(string SiteId, RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(ORenderInfo.Alias))
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null)
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }
                CmsDataCls[] MenuItems = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingCmsDataIsPublic(SiteId, OGroupData.GroupDataId, null);
                string Html = "";
                for (int iIndex = 0; iIndex < MenuItems.Length; iIndex++)
                {
                    if (MenuItems[iIndex].DataAlias.ToLower().Equals("footer"))
                    {
                        Html += " <div class=footeritem>" + HttpUtility.HtmlEncode(MenuItems[iIndex].Description) + "</div>\r\n";
                    }
                }
                string k = (string)WebEnvironments.Request(SiteId, "k");
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut BuildSubTreeView(
            string SiteId,
            string GroupDataId,
            string ParentGroupDataFolderId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string Html = "";
                GroupDataFolderCls[] GroupDataFolders =
                    CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingGroupDataFolder(null, SiteId, GroupDataId, ParentGroupDataFolderId);
                Html +=
                    "<ul>\r\n";
                for (int iIndex = 0; iIndex < GroupDataFolders.Length; iIndex++)
                {
                    Html +=
                            "<li id=\"" + GroupDataFolders[iIndex].GroupDataFolderId + "\" class=\"folder expanded\"><a target=\"_self\" href=\"" + GroupDataFolders[iIndex].GroupDataFolderId + "\">" + GroupDataFolders[iIndex].FolderName + "</a>\r\n" +
                                BuildSubTreeView(SiteId, GroupDataId, GroupDataFolders[iIndex].GroupDataFolderId).HtmlContent +
                            "</li>\r\n";
                }

                Html += "</ul>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        public static AjaxOut RenderFolder(
            string SiteId,
            RenderInfoCls ORenderInfo)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                GroupDataCls OGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, ORenderInfo.Alias);
                if (OGroupData == null)
                {
                    throw new Exception("Tham số truy vấn không hợp lệ!");
                }

                string gdf = (string)WebEnvironments.Request(SiteId, "gdf");
                if (string.IsNullOrEmpty(gdf)) gdf = "";
                string gid = OGroupData.GroupDataId;
                GroupDataFolderCls[] GroupDataFolders =
                    CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingGroupDataFolder(null, SiteId, gid, null);
                if (GroupDataFolders.Length == 0)
                {
                    OAjaxOut.HtmlContent = "<input id=txtCheckFolder value=\"0\" type=hidden>";
                    return OAjaxOut;
                }
                string Html =
                    "<input id=txtCheckFolder value=\"1\" type=hidden>\r\n" +
                    "<div class=TreeHolder>\r\n" +
                    "<div id=\"tree\">\r\n" +
                    "<ul>\r\n" +
                    " <li id=\"root\" class=\"folder expanded\"><a href=\"root\" target=\"_self\">" + OGroupData.GroupDataName + "</a></a>\r\n" +
                    "     <ul>\r\n";
                for (int iIndex = 0; iIndex < GroupDataFolders.Length; iIndex++)
                {
                    Html +=
                            "<li class=\"folder expanded\" id=\"" + GroupDataFolders[iIndex].GroupDataFolderId + "\"><a href=\"" + GroupDataFolders[iIndex].GroupDataFolderId + "\" target=\"_self\">" + GroupDataFolders[iIndex].FolderName + "</a>\r\n" +
                                    BuildSubTreeView(SiteId, gid, GroupDataFolders[iIndex].GroupDataFolderId).HtmlContent +
                            "</li>\r\n";
                }

                Html += "</ul>\r\n" +
                        "</li>\r\n" +
                        "</ul>\r\n" +
                        "</div><br>\r\n" +
                        "<script language=javascript>\r\n" +
                        "   function setActiveNode()\r\n" +
                        "   {\r\n" +
                        "       ActiveClick = false;\r\n" +
                        "       $(\"#tree\").dynatree(\"getTree\").activateKey(\"" + gdf + "\");\r\n" +
                        "       ActiveClick = true;\r\n" +
                        "   }\r\n" +
                        "</script>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

    }
}

